2012-07-13 161 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