2017-07-02 238 views
0

這是我的數據和圖表的樣本:GGPLOT2:改變酒吧的順序,使數值越小酒吧都在酒吧頂部具有較大值

m <- c("jun","jun","jul","aug","aug") 
a <- c(1,10,2,10,2) 
b <- c("x","y","x","x","y") 

df <- data.frame(m,a,b) 

ggplot(df, 
     aes(x=m, y=a, fill=b)) + 
    geom_bar(stat="identity", position = "identity") 

enter image description here

我想x值顯示在jun欄上。我想想要酒吧在彼此頂部不是並排。

我結束了使用透明度。但我仍然很好奇,如果他們是另一種方式去做。

+1

爲什麼你不希望使用'位置=「道奇」'? –

+0

刪除position =「identity」,x值爲1將顯示在Jun欄上 – aelwan

回答

1

我會做什麼:

ggplot(df, aes(x = m, y = a, fill = b)) + 
    geom_bar(stat = "identity", position = position_dodge(preserve = "single")) 

enter image description here

請確保您有最新版本的GGPLOT2devtools::install_github("tidyverse/ggplot2")

0

使用透明度得到我想要什麼:

ggplot(df, 
     aes(x=m, y=a, fill=b)) + 
    geom_bar(stat="identity", position = "identity", alpha=0.5)