作为一个问题,我试图使用以下代码创建图:
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()
Run Code Online (Sandbox Code Playgroud)
使用scale_y_continuous(trans = 'reverse'),我无法使用ylimit(即,无法在ylimit中看到调整),我也不知道为什么。有什么建议么?谢谢。
如Hadley所建议:使用scale_continuous的limits参数。请参阅:http://had.co.nz/ggplot2/scale_continuous.html
例如。:
scale_y_continuous(trans = 'reverse', limits=c(0, 1500))
在您的示例中,您看不到调整,因为您用最后一个scale_y_continuous参数覆盖了之前定义的限制。
祝好运!
| 归档时间: |
|
| 查看次数: |
3469 次 |
| 最近记录: |