当使用“scale_y_continuous(trans = ‘reverse’)”时,不能在 ggplot 中使用 ylimit
作为问题,我尝试使用以下代码创建一个绘图:
chart.demo.sex.age <- ggplot(psf10[!is.na(psf10[,"age_gp"]),c("sex","age_gp")], aes(x=age_gp))
chart.demo.sex.age.f <- chart.demo.sex.age + geom_bar(subset = .(sex =="F"), fill="red")
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_x_discrete(expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(limits=c(0,1500), expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + opts(axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
panel.border = theme_rect(colour="black"),
plot.margin = unit(c(1,0,1,1),"lines"))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(trans = 'reverse') + coord_flip()
使用 scale_y_continuous(trans = 'reverse')
,我无法使用 ylimit
(即我可以'没有看到 ylimit 的调整),我不知道为什么。有什么建议吗?谢谢。
As question, I am trying to create a plot using the following code:
chart.demo.sex.age <- ggplot(psf10[!is.na(psf10[,"age_gp"]),c("sex","age_gp")], aes(x=age_gp))
chart.demo.sex.age.f <- chart.demo.sex.age + geom_bar(subset = .(sex =="F"), fill="red")
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_x_discrete(expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(limits=c(0,1500), expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + opts(axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
panel.border = theme_rect(colour="black"),
plot.margin = unit(c(1,0,1,1),"lines"))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(trans = 'reverse') + coord_flip()
With scale_y_continuous(trans = 'reverse')
, I can't use ylimit
(i.e. i can't see adjustment in ylimit), I don't know why. Any suggestions? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如Hadley建议的那样:使用scale_continuous的limits参数。请参阅:http://had.co.nz/ggplot2/scale_continuous.html
例如。 :
scale_y_continuous(trans = 'reverse', limit=c(0, 1500))
在您的示例中,您看不到调整,因为您用最后一个
scale_y_continuous
参数覆盖了限制之前定义的。祝你好运!
As Hadley suggested: use the limits parameter of scale_continuous. See: http://had.co.nz/ggplot2/scale_continuous.html
Eg.:
scale_y_continuous(trans = 'reverse', limits=c(0, 1500))
In your example you cannot see the adjustment, because your overwrite with your last
scale_y_continuous
paramater the limits defined before.Good luck!