【问题标题】:cannot use ylimit in ggplot when used "scale_y_continuous(trans = 'reverse')"使用“scale_y_continuous(trans = 'reverse')”时不能在 ggplot 中使用 ylimit
【发布时间】:2010-12-31 05:05:05
【问题描述】:

作为问题,我正在尝试使用以下代码创建一个情节:

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 中看不到调整),我不知道为什么。有什么建议么?谢谢。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    正如 Hadley 建议的那样:使用 scale_continuous 的 limits 参数。见:http://had.co.nz/ggplot2/scale_continuous.html

    例如: scale_y_continuous(trans = 'reverse', limits=c(0, 1500))

    在您的示例中,您看不到调整,因为您使用最后一个 scale_y_continuous 覆盖之前定义的限制。

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2016-01-08
      • 2014-01-18
      相关资源
      最近更新 更多