在不同的图ggplot2中保持相同的比例 [英] Keep same scale in different graphs ggplot2

查看:127
本文介绍了在不同的图ggplot2中保持相同的比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ggplot(observbest,aes(x = factor(iteration)) ,y = bottles,color = Team,group = Team))+ geom_line()+ scale_colour_gradientn(colors = rainbow(16))
ggplot(observmedium,aes(x =因子(iteration),y = bottles,color =团队,组=团队))+ geom_line()+ scale_colour_gradientn(颜色=彩虹(16))
ggplot(observweak,aes(x = factor(iteration),y = bottles,color = Team,group = Team ))+ geom_line()+ scale_colour_gradientn(colors = rainbow(16))

每次显示差异数据集都是一样的。我想在它们之间进行比较,因此我希望它们的y轴固定在所有图形上具有相同边距的相同比例尺上,这种情况目前不会自动发生。



<任何建议?



谢谢

解决方案

听起来像一个 facet_wrap ,所有的观察结果都合并成一个数据框,可能就是你要找的东西。例如。

  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)


I want to create 3 graphs in ggplot2 as follows:

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.

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. E.g.

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)

这篇关于在不同的图ggplot2中保持相同的比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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