我来自这个post,回答如何将文本添加到文本到情节中.然而,我的问题不止于此,因为我需要在多个位置多次添加文本.注解函数似乎不起作用,我try 了geom_text,但不知何故我无法使其成为WOKR

我怎么能这样做,添加多个"+","++"或"*"

enter image description here

我在这里留下我的数据库:

p1 <- ggplot(data = df_plot2, aes( x = RQ_gapdh, y = gen, xmin = after_scale(1),
  fill = Color)) +
  geom_col(width = .5) +
    scale_fill_manual(values = c("indianred1", "olivedrab3" ))+
  labs(
    y = "Genes", x = expression(2^{-Delta*Delta*Ct}),
    title = "Gene expression",
    subtitles = "1 year post-intervention") +   
  guides(fill = "none") +
  facet_wrap(~grup_int,
    labeller = labeller(
      grup_int = c(
        "1" = "Olive oil",
        "2" = "Nuts",
        "3" = "Low-fat diet"
      )
    )
  )  + 
  theme(axis.text.y = element_text(face = "italic", family = "serif"))+
   geom_vline(xintercept = 1, linetype = "dashed", color = "black")+
     scale_x_continuous(limits = c(0.75, 1.25), breaks = c(0.75, 1, 1.25))


df_plot2<- structure(list(gen = structure(c(11L, 11L, 11L, 10L, 10L, 10L, 
9L, 9L, 9L, 8L, 8L, 8L, 7L, 7L, 7L, 6L, 6L, 6L, 5L, 5L, 5L, 4L, 
4L, 4L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L), levels = c("SCARB1", 
"RXRB", "RXRA", "PPARG", "PPARD", "PPARA", "NR1H3", "NR1H2", 
"CAV1", "ABCG1", "ABCA1"), class = "factor"), grup_int = structure(c(3L, 
2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 
1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L
), levels = c("1", "2", "3"), class = "factor"), time = c("3", 
"3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
"3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
"3", "3", "3", "3", "3", "3"), RQ_gapdh = c(1.019, 1.218, 1.183, 
0.926, 1.132, 1.052, 0.944, 0.9, 0.947, 0.936, 1.117, 0.961, 
0.987, 1.182, 0.971, 1.008, 0.985, 0.951, 0.935, 1.149, 1.058, 
0.914, 1.01, 0.952, 0.913, 1.134, 1.112, 0.985, 1.074, 1.135, 
1.019, 1.138, 0.989), Color = structure(c(2L, 2L, 2L, 1L, 2L, 
2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 
1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L), levels = c("FALSE", 
"TRUE"), class = "factor")), row.names = c(8L, 19L, 30L, 11L, 
22L, 33L, 10L, 21L, 32L, 5L, 16L, 27L, 4L, 15L, 26L, 1L, 12L, 
23L, 2L, 13L, 24L, 3L, 14L, 25L, 6L, 17L, 28L, 7L, 18L, 29L, 
9L, 20L, 31L), class = "data.frame")

推荐答案

根据 comments 中的基本说明,在目标gengrup_int组合中添加注释,以便这些组合可以与geom_text()一起使用,以前几个为例:

library(ggplot2)
library(dplyr)

df_plot2 %>% 
  mutate(annotation = case_when(gen == "ABCA1" & grup_int == 1 ~ "++",
                                gen == "PPARD" & grup_int == 1 ~ "+" ,
                                gen == "ABCG1" & grup_int == 2 ~ "+++" ,
                                gen == "NR1H2" & grup_int == 2 ~ "+" )) %>% 
ggplot(aes( x = RQ_gapdh, y = gen, xmin = after_scale(1),
  fill = Color)) +
  geom_col(width = .5) +
    scale_fill_manual(values = c("indianred1", "olivedrab3" ))+
  geom_text(aes(label = annotation), nudge_x = .01, hjust = "left", fontface = "bold") +
  labs(
    y = "Genes", x = expression(2^{-Delta*Delta*Ct}),
    title = "Gene expression",
    subtitles = "1 year post-intervention") +   
  guides(fill = "none") +
  facet_wrap(~grup_int,
    labeller = labeller(
      grup_int = c(
        "1" = "Olive oil",
        "2" = "Nuts",
        "3" = "Low-fat diet"
      )
    )
  )  + 
  theme(axis.text.y = element_text(face = "italic", family = "serif"))+
   geom_vline(xintercept = 1, linetype = "dashed", color = "black")+
     scale_x_continuous(limits = c(0.75, 1.25), breaks = c(0.75, 1, 1.25))
#> Warning: Removed 29 rows containing missing values (`geom_text()`).

创建于2023-11-20,共reprex v2.0.2

R相关问答推荐

手工PCA上的载体与输出双图不匹配

将Multilinetring合并到一个线串中,使用sf生成规则间隔的点

为什么st_join(ob1,ob2,left = True)返回具有比ob1更多功能的sf对象?

使用tidyverse / Mutate的存款账户余额

R Sapply函数产生的值似乎与for循环方法略有不同

如何在格子中添加双曲曲线

在R中将特定列的值向右移动

为什么舍入POSIXct会更改能力以匹配等效的POSIXct?

合并DFS列表并将索引提取为新列

矩阵的堆叠条形图,条形图上有数字作为标签

R:从geom_ol()中删除轮廓并导出为pdf

在使用tidyModels和XGBoost的二进制分类机器学习任务中,所有模型都失败

R:用GGPLATE,如何在两个独立的变量中制作不同形状的散点图?

在列表中排列R数据框中的列顺序

将项粘贴到向量中,并将它们分组为x的倍数,用空格分隔

远离理论值的伽马密度曲线下面积的近似

数据集上的R循环和存储模型系数

是否有一个R函数可以输出在输入的字符向量中找到的相应正则表达式模式?

ArrangeGrob()和类似的替代方法不接受Grob列表.在Grid.Draw,返回:glist中的错误(...):仅允许在glist";中使用Grobs;

无法保存gglot的所有pdf元素