2017-07-02 236 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)