简体   繁体   English

在不同的图形ggplot2中保持相同的比例

[英]Keep same scale in different graphs ggplot2

I want to create 3 graphs in ggplot2 as follows: 我想在ggplot2中创建3个图形,如下所示:

ggplot(observbest,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16)) 
ggplot(observmedium,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16))
ggplot(observweak,aes(x=factor(iteration),y=bottles,colour=Team ,group=Team)) + geom_line() + scale_colour_gradientn(colours=rainbow(16))

That is, three graphs displaying the same thing but for difference dataset each time. 也就是说,三个图表显示相同的内容,但每次都显示差异数据集。 I want to compare between them, therefore I want their y axis to be fixed to the same scale with the same margins on all graphs, something the currently doesn't happen automatically. 我想在它们之间进行比较,因此我希望它们的y轴固定在所有图形上具有相同边距的相同比例,这是当前不会自动发生的。

Any suggestion? 有什么建议吗?

Thanks 谢谢

It sounds like a facet_wrap on all the observations, combined into a single dataframe, might be what you're looking for. 听起来像所有观察结果的facet_wrap ,结合成一个数据帧,可能就是你正在寻找的。 Eg 例如

library(plyr)
library(ggplot2)

observ <- rbind(
  mutate(observbest, category = "best"),
  mutate(observmedium, category = "medium"),
  mutate(observweak, category = "weak")
)

qplot(iteration, bottles, data = observ, geom = "line") + facet_wrap(~category)

在此输入图像描述

Add + ylim(min_value,max_value) to each graph. + ylim(min_value,max_value)到每个图形。

Another option would be to merge the three datasets with an id variable identifying which value is in which dataset, and then plot the three of them together, differentiating them by linetype for instance. 另一种选择是将三个数据集与一个id变量合并,以识别哪个值在哪个数据集中,然后将它们中的三个一起绘制,例如通过linetype区分它们。

使用scale_y_continuous为每个图形定义y轴,并使它们都易于比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM