cannot use ylimit in ggplot when used "scale_y_continuous(trans = 'reverse')"
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.
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!
精彩评论