使用 ggplot2 在一个画布中绘制多个图形 [英] multiple graphs in one canvas using ggplot2

查看:64
本文介绍了使用 ggplot2 在一个画布中绘制多个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据此表将两个 ggplot2 图合并为一个:

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

我想绘制两个散点图,y 轴为评分平均值,x 轴为输入.

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")

由于 p1 和 p2 具有相同的 x 轴,我希望它们垂直排列.我查看了 facet_align,但找不到可以完成这项工作的内容.

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.

推荐答案

你可以像这样在 gridExtra 包中使用 grid.arrange() :

You can use grid.arrange() in the gridExtra package like this:

grid.arrange(p1, p2)

这篇关于使用 ggplot2 在一个画布中绘制多个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆