R:由于数学标题符号,arrange.grid不同的地块大小

问题描述 投票:2回答:2

我是设计情节的新手,我尝试用以下方法构建条形图:

bar <- ggplot(month1, aes(x=variable, y=value, fill=merge1)) + geom_bar(stat="identity")
bar_f <- bar  + ggtitle("k = 0") + theme(axis.text=element_text(size=12, color="gray0"), 
axis.title=element_blank()) 
+ scale_y_continuous(breaks= function(x) unique(floor(pretty(seq(0, (max(x) + 1) * 1.1))))) 
+ scale_fill_manual(values= grp_colors, guide=F) 


bar2 <- ggplot(month2, aes(x=variable, y=value, fill=merge2)) + geom_bar    (stat="identity") 
bar2_f <- bar2 + ggtitle(expression(k %in% group("[", "1;12", "]"))) 
+ theme(axis.text=element_text(size=12 , color="gray0"), axis.title=element_blank()) 
+ scale_y_continuous(limits=c(0,3), breaks=seq(3)) + scale_fill_manual(values= grp_colors, guide=F)

combine <- gridExtra::grid.arrange(bar_f, bar2_f, nrow=1, top= textGrob("Monatsdaten: Häufigkeiten", gp=gpar(fontsize=20,font=1)))

我的问题是,我在我的bar2情节中有一个数学符号,由

expression(k %in% group("[", "1;12", "]"))

如果我将标题更改为“正常”标题,则两个图的大小相等。显然,第二个图有点小,由数学标题引起。我试图在ggplot环境之外和grid.arrange中定义,但它不能用表达式表示法。有没有办法有相同大小的情节对象?

另一个(这不是我的主要问题,但我没有找到答案)问题,我可以扩大我的头衔和情节标题之间的距离吗?

enter image description here

r ggplot2 r-grid
2个回答
0
投票

试试cowplot

# some plots
p <- ggplot(iris, aes(Species, Sepal.Length)) +
          stat_summary(geom="bar", fun.y="mean")

p1 <- p + ggtitle("k=0")    
p2 <- p + ggtitle(expression(k %in% group("[", "1;12", "]"))) 

# the plot. Add horizontal alignment
cowplot::plot_grid(p1, p2, align = "h")

enter image description here


0
投票

grid.arrange有一个“高度”选项,您可以在其中更改绘图相对于彼此的大小。你会添加一个术语

heights =c(1,1.1) 

到你的grid.arrange调用,使你的第二个绘图的绘制区域略大。有关示例,请参阅Specify widths and heights of plots with grid.arrange

© www.soinside.com 2019 - 2024. All rights reserved.