我有一个数据,其中一个分类变量有3个水平。现在分别对每一个水平分别进行作图,并用gridExtra包中的grid.arrange函数进行组合。每一个图形都有相同的图例,组合后为了减少重复,减去两个图例,即中间图形保留图例,两边的图形不显示图例。但是这样一来,组合后的三张图形比例不是一致。问各位高手怎么解决?

下面是我的数据以及代码:
#Data building ####
BXTgrowth <- data.frame(tissue = rep(c("Body", "PEM", "GAC"), each = 6),
                        time = rep(c("25", "27", "35"), each = 2, times = 3),
                        kcl = rep(c("con", "tre"), times = 9),
                        mean = c(32.3, 33.5, 42.3, 48.6, 71.1, 78.4,
                                 226, 241, 186, 212, 202, 231,
                                 100, 103, 145, 156, 258, 270),
                        se = c(0.99, 0.87, 1.8, 1.2, 3.3, 3.3,
                               9.26, 7.82, 9.77, 2.72, 7.23, 10.06,
                               8.10, 6.47, 7.41, 7.80, 11.50, 13.95))

#Three figurs
p1 <- BXTgrowth %>%
    filter(tissue == "Body") %>%
    ggplot(aes(x = time, y = mean, fill = kcl)) +
    geom_bar(position = "dodge", stat = "identity", colour = "black") +
    labs(x = "Times", y = "Weight of body (g)") +
    scale_x_discrete(labels = c("Eday 25", "Eday 27", "Day 7")) +
    scale_fill_grey(guide = guide_legend(title = NULL),
                    labels = c("Control group", "Treatment group")) +
    geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                  position = position_dodge(0.9), width = 0.2) +
    annotate(geom = "text", x = c(2, 3),
             y = c(48.6 + 5, 78.4 + 5), label = "*") +
    theme_bw() +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          legend.position = "none",
          axis.title = element_text(family = "Times New Roman", size = 15),
          legend.text = element_text(family = "Times New Roman", size = 12),
          axis.text = element_text(family = "Times New Roman", size = 8))
p2 <- BXTgrowth %>%
    filter(tissue == "PEM") %>%
    ggplot(aes(x = time, y = mean, fill = kcl)) +
    geom_bar(position = "dodge", stat = "identity", colour = "black") +
    labs(x = "Times", y = "Weight of PEM (mg)") +
    scale_x_discrete(labels = c("Eday 25", "Eday 27", "Day 7")) +
    scale_fill_grey(guide = guide_legend(title = NULL),
                    labels = c("Control group", "Treatment group")) +
    geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                  position = position_dodge(0.9), width = 0.2) +
    theme_bw() +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          legend.position = "top",
          axis.title = element_text(family = "Times New Roman", size = 15),
          legend.text = element_text(family = "Times New Roman", size = 12),
          axis.text = element_text(family = "Times New Roman", size = 8))
p3 <- BXTgrowth %>%
    filter(tissue == "GAC") %>%
    ggplot(aes(x = time, y = mean, fill = kcl)) +
    geom_bar(position = "dodge", stat = "identity", colour = "black") +
    labs(x = "Times", y = "Weight of GAC (mg)") +
    scale_x_discrete(labels = c("Eday 25", "Eday 27", "Day 7")) +
    scale_fill_grey(guide = guide_legend(title = NULL),
                    labels = c("Control group", "Treatment group")) +
    geom_errorbar(aes(ymin = mean - se, ymax = mean + se),
                  position = position_dodge(0.9), width = 0.2) +
    annotate(geom = "text", x = c(2, 3),
             y = c(156 + 5, 270 + 5), label = "*") +
    theme_bw() +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          legend.position = "none",
          axis.title = element_text(family = "Times New Roman", size = 15),
          legend.text = element_text(family = "Times New Roman", size = 12),
          axis.text = element_text(family = "Times New Roman", size = 8))
ps <- grid.arrange(grobs = list(p1, p2, p3), ncol =3)
ps

如果图形显示不了的话,点击这个网址
必须要分开来做图吗?不可以使用分面吗?

BXTgrowth %>%
  ggplot(aes(x = time, y = mean, fill = kcl))+
  geom_bar(stat='identity', position= 'dodge', colour= 'black')+
  facet_wrap(~tissue)
我感觉效果是一样的。

不过你提到的这个问题,自己还没注意过呢,等待高手。
如果还按照你的做法来,可以尝试给第一张图和第三张图上面的margin设置大一些;
我给它们加上下面一句(做出来的图还行)

plot.margin=unit(c(4, 1, 0.5, 0.5),units= 'line')

refer: http://stackoverflow.com/questions/17073772/ggplot2-legend-on-top-and-margin
[未知用户]
谢谢你的回复。分面我也尝试过。但是由于各个分面子图添加的“*”位置不一样,这个不好处理吧?如果你能够解决这个问题,那就更好了,可以直接分面解决。
7 天 后
@刘 宏祥</a>:
哦,原来是这样,没看到你的图片中还有一个*号呢。你说的这个问题 ,还是头一次碰到呢,学习了。
在不同的分面中(或者指定的分面里)添加不同的注释(或者符号),这个一搜就有答案了。

http://stackoverflow.com/questions/11889625/annotating-text-on-individual-facet-in-ggplot2#412920#412943#5

大概就是需要创建一个data.frame,然后把表示横、纵坐标和因子的变量都设置好,就可以在指定的分面里添加星号了。

ps:你的图画的真不错。 :-)

6 天 后
[未知用户]
谢谢,你建议的这个帖子正是我想要的。 :D
4 天 后
[未知用户]
对了,你知道怎么在坐标轴标题中添加公式吗?