使用ggplot2在一个画布中绘制多个图形 [英] multiple graphs in one canvas using ggplot2
本文介绍了使用ggplot2在一个画布中绘制多个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类型评分A评分B
1我试图将两个ggplot2图合并为一个基于此表的表:一个3 36
2两个5 53
3一个5 57
4一个7 74
5三个4 38
6三个8 83
我想制作两个散点图,分别是y轴的评分和x轴的评分。
这是我创建每张图的方式:
p1 < - ggplot(test ,aes(x = reorder(Type,RatingA,mean),y = RatingA))+
stat_summary(fun.y =mean,geom =point)
p2 < ; - ggplot(test,aes(x = reorder(Type,RatingB,mean),y = RatingB))+
stat_summary(fun.y =mean,geom =point)
由于p1和p2具有相同的x轴,所以我希望它们是垂直排列的。
解决方案
您可以使用网格.grid()
在gridExtra包中是这样的:
grid.arrange(p1,p2)
I am trying to merge two ggplot2 plots into one based on this table:
Type RatingA RatingB
1 One 3 36
2 Two 5 53
3 One 5 57
4 One 7 74
5 Three 4 38
6 Three 8 83
I want to make two scatter plots with the mean of the ratings in the y axis and type on the x axis.
This is how I create each graph:
p1 <- ggplot(test, aes(x=reorder(Type, RatingA, mean), y=RatingA)) +
stat_summary(fun.y="mean", geom="point")
p2 <- ggplot(test, aes(x=reorder(Type, RatingB, mean), y=RatingB)) +
stat_summary(fun.y="mean", geom="point")
Since p1 and p2 have the same x axis I would like them to be ordered vertically. I looked at facet_align but I couldnt find something that would do the job.
解决方案
You can use grid.arrange()
in the gridExtra package like this:
grid.arrange(p1, p2)
这篇关于使用ggplot2在一个画布中绘制多个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文