在带有Cowplot的ggplot-grid构建中添加x和y laxis标签 [英] Adding x and y laxis label to ggplot-grid build with cowplot
问题描述
我用Cowplot制作了一个网格:
库(ggplot2)图书馆(cowplot)ggg1<-ggplot(mtcars,aes(mpg,vs))+ geom_point()+主题(axis.title.x = element_blank(),axis.title.y = element_blank())ggg2<-ggplot(mtcars,aes(mpg,vs))+ geom_point()+主题(axis.title.x = element_blank(),axis.title.y = element_blank())ggg3<-ggplot(mtcars,aes(mpg,vs))+ geom_point()+主题(axis.title.x = element_blank(),axis.title.y = element_blank())plot_grid(plot_grid(ggg1,ggg2,labels = c(","),ncol = 1),ggg3,labels = c(","),ncol = 2)
产生图片
(当然,这只是一个最小的工作示例).
现在,我想有一个标题为"mpg"的xaxis和一个标题为"vs"的yaxis-每个居中位置都像这样:
如何使用ggplot做到这一点.我没有尝试使用 add_sub
或 draw_label
或
I produced a grid with cowplot:
library(ggplot2)
library(cowplot)
ggg1 <- ggplot(mtcars, aes(mpg,vs)) + geom_point() +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank())
ggg2 <- ggplot(mtcars, aes(mpg,vs)) + geom_point() +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank())
ggg3 <- ggplot(mtcars, aes(mpg,vs)) + geom_point() +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank())
plot_grid(plot_grid(ggg1, ggg2, labels=c("", ""), ncol = 1), ggg3, labels=c("", ""), ncol = 2)
resulting in the image
(of course this is just a minimal working example).
Now I would like to have a xaxis with the title "mpg" and a yaxis with the title "vs" - each centered like so:
How can I do this with ggplot. Nothing I tried with add_sub
or draw_label
or How do I customize the margin and label settings with plot_grid? worked. The answer to ggplot: how to add common x and y labels to a grid of plots does not use cowplot. Can I do this with cowplot?
Important: I want to be able to set the size of the font of the labels.
This seems to work...
plot_grid(plot_grid(ggg1, ggg2, labels=c("", ""), ncol = 1),
ggg3,
labels=c("", ""),
ncol =2,
scale=0.9) + #perhaps reduce this for a bit more space
draw_label("xlab", x=0.5, y= 0, vjust=-0.5, angle= 0) +
draw_label("ylab", x= 0, y=0.5, vjust= 1.5, angle=90)
这篇关于在带有Cowplot的ggplot-grid构建中添加x和y laxis标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!