ggplot中的各个方面是否有可能具有不同的坐标轴断点/限制以及自由缩放比例? [英] Is it yet possible to have different axis breaks / limits for individual facets in ggplot with free scale?

查看:200
本文介绍了ggplot中的各个方面是否有可能具有不同的坐标轴断点/限制以及自由缩放比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个相关问题在2010年被问到(标题为:你如何为不同的方面设置不同的比例限制?),并想知道是否有可能针对不同的方面有不同的休息时间?



原因在于我只想在下图中的整数值(顶部图表的中断为50):

重现图片的代码:



<$ (date = seq(0,729,1),Var1 = round(seq(from = 0,length.out = 730,by = 0.2)) ,var2 = round(seq(from = 5,length.out = 730,by = 0.01)))
dat.m< - melt(dat,id.var =date)
ggplot (dat.m,aes(date,value))+
scale_x_continuous(name =Time)+
expand_limits(y = 0)+
ylab(Variable)+
geom_step() +
facet_grid(variable〜。,scales =free_y)+
scale_y_continuous(breaks = seq(0,150,by = 1))
pre>

解决方案

首先,您的代码不会像我的机器上产生相同的情节。你可以提供 sessionInfo()



我不认为这是可能的。您可以通过简单的方式实现最佳逼真度:

  ggplot(dat.m,aes(date,value)) + 
scale_x_continuous(name =Time)+
expand_limits(y = 0)+
ylab(Variable)+
geom_step()+
facet_grid(
scale_y_continuous(breaks = c(seq(0,12,by = 2),seq(0,150,by = 50)))


I saw that this related question was asked in 2010 (titled: How do you set different scale limits for different facets?) and would like to know if it is yet possible to have different breaks for different facets?

The reason being is that I want only integer values in the lower chart (with breaks of 50 for the top chart) of following plot:

Code to reproduce the image:

dat <- data.frame(date=seq(0, 729, 1), Var1=round(seq(from=0, length.out=730, by=0.2)),   Var2=round(seq(from=5, length.out=730, by=0.01))  )
dat.m <- melt(dat, id.var="date")
ggplot(dat.m, aes(date,  value)) + 
      scale_x_continuous(name="Time") + 
      expand_limits(y=0) +
      ylab("Variable") + 
      geom_step() + 
      facet_grid(variable~., scales="free_y")+ 
      scale_y_continuous(breaks = seq(0, 150, by = 1))

解决方案

First, your code doesn't produce the same plot as on my machine. Can you provide the sessionInfo()?

I don't think it is possible. Best approximation of your request I could achieve in a simple way:

ggplot(dat.m, aes(date,  value)) + 
      scale_x_continuous(name="Time") + 
      expand_limits(y=0) +
      ylab("Variable") + 
      geom_step() + 
      facet_grid(variable~., scales="free_y")+ 
      scale_y_continuous(breaks = c(seq(0, 12, by = 2),seq(0, 150, by = 50)))

这篇关于ggplot中的各个方面是否有可能具有不同的坐标轴断点/限制以及自由缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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