2016-08-03 51 views
2

我有一個條形圖,看起來像這樣:移位geom_bar權(不居中對齊)

ggplot(mtcars, aes(x = cyl, y = hp)) + 
    geom_bar(stat = "identity", width = 1) 

我想調整的geom_bar參數,使杆右移(不居中) ...

enter image description here

回答

8

試試這個:

ggplot(mtcars, aes(x = cyl, y = hp)) + 
geom_bar(stat = "identity", width = 1, position = position_nudge(x = 0.5)) 

我如何想通了:去了?geom_bar,看到有一個位置參數和鏈接到?position_dodge。看看那裏的例子,並修改你的代碼。似乎是一個令人滿意的解決方案。

+0

我想擺弄position_dodge ......但它不工作。 position_ * nudge *()正是我所需要的。謝謝! – emehex