2012-07-13 218 views
4
test <- data.frame(
    y=seq(18,41,1), 
    x=24:1 
) 

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts(axis.text.x = theme_blank(), axis.ticks.x = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + 
    coord_cartesian(ylim = c(17, 42)) 

enter image description hereggplot geom_bar - '旋转并翻转'?

至于旋转和翻转而言,我喜欢在这个情节y轴是沿顶,什么是要倒右手x轴侧。所以酒吧是从情节的右手边出来的,最长/最高的在最上面,最短的在最下面。如果它顺时针旋转90度,然后翻转一条实现它的垂直线。

coord_flip()和scale_y_reverse()沿着正确的路径前进。

编辑:

我想这是非常接近,只需要得到Y轴图表的顶部。

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts(axis.text.y = theme_blank(), axis.ticks.y = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + scale_y_reverse() + coord_flip() + scale_x_reverse() 

回答

9

不完全是你所描述的,但也许够接近?

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    coord_flip() + 
    xlim(24, 1) + 
    ylim(42, 0) 

诀窍是具有以相反的顺序xlimylim参数。你的轴位置仍然是底部和左侧...

enter image description here

+0

@nzcoops对您有帮助呢? – Andrie 2012-07-19 09:05:48