如何设置包围y轴的圆面的限制? [英] how to set limits on rounded facet wrap y axis?
问题描述
我有这个阴谋,我需要围绕y轴,所以看起来是可以接受的,除非我想不只是在y轴上显示1个值。我想将限制添加到scale_y_continuous函数中,以便每个方面图的限制对于各个方面都是唯一的。这里是图只在y轴上显示60和80
dat = data.frame(x = c(1,2,3,1 ,A = c(80.6,82,83,60,61,62),A_up = c(81,84,85,62,63,64),A_low = c(79,78,81, (x = 59,58,57),group = c(z,z,z,y,y,y))
ggplot(data = dat,aes(x = as.factor(x),y = A,group = 1))+#,color = Group,group = Group
geom_line()+ geom_point()+#facet_wrap(〜COUNTERPARTY_STRATEGY,ncol = 2)
geom_errorbar(aes(ymax = A_up,ymin = A_low),width = .25)+
scale_y_continuous(breaks = seq(floor((min(dat $ A_low)-11)/ 10)* 10,
ceiling((max(dat $ A_up)+11)/ 10)* 10,10),
labels = seq(floor((min(dat $ A_low)-11)/ 10)* 10,
上限((max(dat $ A_up)+11)/ 10)* 10,10)
)+
facet_wrap(〜group,ncol = 2,scales =free_y)
dat = data.frame(x = c(1) ,A = c(80.6,82,83,60,61,62),A_up = c(81,84,85,62,63,64),A_low = c( 79,78,81,59,58,57),group = c(z,z,z,y,y,y))
ggplot(data = dat,aes(x = as.factor(x),y = A,group = 1))+#,color = Group,group = Group
geom_line()+ geom_point()+#facet_wrap(〜COUNTERPARTY_STRATEGY, ncol = 2)
geom_errorbar(aes(ymax = A_up,ymin = A_low),width = .25)+
scale_y_continuous(breaks = seq(floor((min(dat $ A_low)-11)/ 10)$ 10
ceiling((max(dat $ A_up)+11)/ 10)* 10,10),
labels = seq(floor((min(dat $ A_low)-11) / 10)* 10,
ceiling((max(dat $ A_up)+11)/ 10)* 10,10),
#limits = c(floor(min(dat $ A_low [dat $组== 10)$ 10
#limits = c(floor(min((((() dat $ A_low [dat $ group ==z])/ 10)* 10,ceiling(max(dat $ A_up [dat $ group ==z])/ 10)* 10)
limits = c(floor(min(dat $ A_low)/ 10)* 10,ceiling(max(dat $ A_up)/ 10)* 10)
)+
facet_wrap(〜group,ncol = 2,scale =free_y)
即
$ b $ c(floor(min(dat $ A_low)/ 10)* 10,ceiling(max(dat $ A_up)/ 10)* 10 )
是50和90
但我希望限制为每个方面情节都是独一无二的,所以像
这样右边的情节就会有限制
c(floor(min(dat $ A_low [dat $ group ==y])/ 10)* 10,ceiling(max(dat $ A_up [dat $ group ==y])/ 10)* 10)
<50>和<70>
code $ c(floor(min(dat $ A_low [dat $ group ==z])/ 10)* 10,ceiling(max (dat $ A_up [dat $ group ==z])/ 10)* 10)
70和90
如何将限制调整为特定于各个分面图?
<$ (x = c(1,2,3,1,2,3),A = c(80.6,82,83,60,61,62), A_up = c(81,84,85,62,63,64),A_low = c(79,78,81,59,58,57),group = c(z,z,z, y,y,y))
dat < - d ata.table(dat)
dat [,y_min:= floor(min(A_low)/ 10)* 10,by = group]
dat [,y_max:= ceiling(max A_up)/ 10)* 10,by = group]
ggplot(data = dat,aes(x = as.factor(x),y = A,group = 1))+#,color = group,group = Group
geom_line()+ geom_point()+#facet_wrap(〜COUNTERPARTY_STRATEGY,ncol = 2)
geom_errorbar(aes(ymax = A_up,ymin = A_low),width = .25) +
scale_y_continuous(break = seq(floor((min(dat $ A_low)-11)/ 10)* 10,
ceiling((max(dat $ A_up)+11)/ 10)* 10 ,10),
labels = seq(floor((min(dat $ A_low)-11)/ 10)* 10,
ceiling((max(dat $ A_up)+11)/ 10)* 10,10)
)+
facet_wrap(〜group,ncol = 2,scales =free_y)+
geom_blank(aes(y = y_min))+ geom_blank(aes(y = y_max))
所以我在这里使用data.table by = group
为每个组创建 y_min
和 y_max
。然后在 geom_blank
中使用这些值来扩大绘图区域。
显然,这可以自动扩展到任何数量的组/面。
I have this plot and I need to round the y axis so what appears is acceptable EXCEPT for the fact that I would like to not just show 1 value on the y axis. I'd like to add the "limit" to the "scale_y_continuous" function so that the limits for each facet plot are unique to the individual facet.
here is the plot only showing 60 and 80 on the y axis
dat = data.frame(x = c(1,2,3,1,2,3),A=c(80.6, 82,83,60,61,62),A_up =c(81,84,85,62,63,64), A_low =c(79,78,81,59,58,57), group = c("z","z","z","y","y","y"))
ggplot(data=dat , aes(x=as.factor(x), y=A, group = 1)) + #, color =Group, group = Group
geom_line() + geom_point() + # facet_wrap(~COUNTERPARTY_STRATEGY ,ncol=2)
geom_errorbar(aes(ymax = A_up ,ymin = A_low), width = .25) +
scale_y_continuous(breaks = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 ),
labels = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 )
) +
facet_wrap(~group ,ncol=2, scales = "free_y")
Now I add the limit in the scale y continuous and it applies the limit globally.
dat = data.frame(x = c(1,2,3,1,2,3),A=c(80.6, 82,83,60,61,62),A_up =c(81,84,85,62,63,64), A_low =c(79,78,81,59,58,57), group = c("z","z","z","y","y","y"))
ggplot(data=dat , aes(x=as.factor(x), y=A, group = 1)) + #, color =Group, group = Group
geom_line() + geom_point() + # facet_wrap(~COUNTERPARTY_STRATEGY ,ncol=2)
geom_errorbar(aes(ymax = A_up ,ymin = A_low), width = .25) +
scale_y_continuous(breaks = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 ),
labels = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 ),
# limits = c( floor( min(dat$A_low[dat$group =="z"]) /10)*10 ,ceiling(max(dat$A_up[dat$group =="z"])/10)*10 )
#limits = c( floor( min(dat$A_low[dat$group =="z"]) /10)*10 ,ceiling(max(dat$A_up[dat$group =="z"])/10)*10 )
limits = c( floor( min(dat$A_low) /10)*10 ,ceiling(max(dat$A_up)/10)*10 )
) +
facet_wrap(~group ,ncol=2, scales = "free_y")
i.e.
c( floor( min(dat$A_low) /10)*10 ,ceiling(max(dat$A_up)/10)*10 )
is 50 and 90
but I would like the limit to be unique to each facet plot so something like
so the right plot would have limits of
c( floor( min(dat$A_low[dat$group =="y"]) /10)*10 ,ceiling(max(dat$A_up[dat$group =="y"])/10)*10 )
50 and 70
and the left plot would have limit of
c( floor( min(dat$A_low[dat$group =="z"]) /10)*10 ,ceiling(max(dat$A_up[dat$group =="z"])/10)*10 )
70 and 90
how can the limits be adjusted to be specific to the individual facet plots?
dat = data.frame(x = c(1,2,3,1,2,3),A=c(80.6, 82,83,60,61,62),A_up =c(81,84,85,62,63,64), A_low =c(79,78,81,59,58,57), group = c("z","z","z","y","y","y"))
dat <- data.table(dat)
dat[, y_min := floor( min(A_low) /10)*10, by = group]
dat[, y_max := ceiling(max(A_up)/10)*10 , by = group]
ggplot(data=dat , aes(x=as.factor(x), y=A, group = 1)) + #, color =Group, group = Group
geom_line() + geom_point() + # facet_wrap(~COUNTERPARTY_STRATEGY ,ncol=2)
geom_errorbar(aes(ymax = A_up ,ymin = A_low), width = .25) +
scale_y_continuous(breaks = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 ),
labels = seq( floor( (min(dat$A_low)-11) /10)*10 ,
ceiling( (max(dat$A_up)+11) /10)*10,10 )
) +
facet_wrap(~group ,ncol=2, scales = "free_y") +
geom_blank(aes(y = y_min)) + geom_blank(aes(y = y_max))
So here I use data.table by = group
to create y_min
and y_max
for each group. And then use those values in geom_blank
to extend the plot area.
Obviously, this is automatically scalable to any number of groups/facets.
这篇关于如何设置包围y轴的圆面的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!