2017-07-02 5 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

私は希望しますjun barに表示される1のx値。 I バーが互いに重なり合わないようにしたい。

私は透明性を使用して終了しました。しかし、私は彼らがそれをやる別の方法であるかどうかまだ不思議です。私は思い何

+1

は、なぜあなたは 'ポジションを使用したくない='「かわしますか」? –

+0

remove position = "identity"となり、1のx値が6月のバーに表示されます – aelwan

答えて

1

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

enter image description here

あなたはggplot2の最新バージョンであることを確認してください:devtools::install_github("tidyverse/ggplot2")を。

0

透明性は、私が欲しいものを取得します使用:

ggplot(df, 
     aes(x=m, y=a, fill=b)) + 
    geom_bar(stat="identity", position = "identity", alpha=0.5) 
関連する問題