【发布时间】:2019-07-18 19:47:30
【问题描述】:
我有一个多图面板,其中包含我想要修改的注释(图外)。
我该怎么做:
- 将标题(I. 和 II.)移到最左边?
- 更改标题周围的空白数量?
- 更改绘图周围的空白量?
(ggplot() 解决方案首选)
这是获得上述情节的代码(改编自OP)(删除了theme等不需要的代码):
panelA <- data.frame(
Stage = c("Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling"),
Individual = c ("A", "A", "A","B", "B", "B","C", "C", "C","D", "D", "D"),
Score = c( 1.4, 1.2, NA,0.4, 0.6, 0.5,-0.3, -0.5, -0.4,-1.4, -1.2, NA))
A<-ggplot(panelA, aes(x = Stage, y = Score, color =Individual, group= Individual)) +
geom_point() +
geom_line()+
geom_smooth(method=lm, se=F, fullrange=TRUE)
panelB <- data.frame(
Stage = c("Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling"),
Individual = c ("A", "A", "A","B", "B", "B","C", "C", "C","D", "D", "D"),
Score = c( 1.4, 1.2, 1.3,0.4, 0.6, NA,-0.3, -0.5, NA,-1.4, -1.2, -1.3))
B<-ggplot(panelB, aes(x = Stage, y = Score, color =Individual, group= Individual)) +
geom_point() +
geom_line()+
geom_smooth(method=lm, se=F, fullrange=TRUE)
library(ggplot2)
library(gridExtra)
library(RGraphics)
library(cowplot)
grid.newpage()
# Create layout : nrow = 4, ncol = 2
pushViewport(viewport(layout = grid.layout(4, 2)))
# A helper function to define a region on the layout
define_region <- function(row, col){
viewport(layout.pos.row = row, layout.pos.col = col)
}
#text I want to annotate
t1 <- ggdraw() + draw_label("I. Effects on variance components", fontface='bold')
t2 <- ggdraw() + draw_label("II. Effects on means (mediated via plasticity)", fontface='bold')
# Arrange the plots
print(t1, vp=define_region(1, 1))
print(A, vp = define_region(2, 1))
print(B, vp=define_region(2, 2))
print(t2, vp = define_region(3, 1))
print(A, vp=define_region(4, 1))
print(B, vp = define_region(4, 2))
【问题讨论】:
标签: r ggplot2 gridextra annotate cowplot