ggplot - 绘制彼此相邻的2个不同图形

时间:2015-10-26 07:29:19

标签: r plot ggplot2 boxplot

我如何将2个箱形图彼此相邻?

例如,假设我想比较3个足球联赛中“主场平均每场比赛得分”与“主场平均每场比赛失球”,并且为此目的,希望使用彼此相邻的2个盒子图在同一图表(即相同的轴)上给出准确的视觉表示。

我绘制1个盒子图没有问题,但我不知道如何将2个图放在同一个轴上。我看到使用“地图”库的解释,这是唯一的方法吗?

作为参考,我的数据看起来像这样:

    Team Name    Total number of home games  Total goals scored at home  Total Goals conceded at home League

单箱图的代码:

ggplot(data=final, aes(x=factor(League),
y=(((GS.Home/Total.Home.Games))), colour=League)) + 
geom_boxplot() + geom_point() + stat_summary(fun.y=mean,
geom="point", shape=5, size=4)+ xlab("League")+ 
ylab("Avg goals scored per Home Game")+ 
ggtitle("Average points per Home Game across Leagues")

1 个答案:

答案 0 :(得分:1)

你正在寻找这样的东西吗?

enter image description here

<email@abc.com>"
相关问题