当使用“scale_y_continuous(trans = ‘reverse’)”时,不能在 ggplot 中使用 ylimit

发布于 2024-10-10 00:07:58 字数 1183 浏览 0 评论 0原文

作为问题,我尝试使用以下代码创建一个绘图:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霓裳挽歌倾城醉 2024-10-17 00:07:58

正如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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文