3
aes
のfill
引数を指定すると、円グラフの逆順になります。したがって、改行/ラベルは、もはや円の部分と一致しません。以下の例とその結果のプロットを参照してください。ggplot2 coord_polar fillを使用するときの順序を保持する
df = data.frame(Var1 = letters[1:5], Var2 = c(6, 31, 34, 66, 77))
df$Var1 = factor(df$Var1, levels = df$Var1, ordered = T)
# just fine, but no colors
ggplot(df, aes(x = 1,
y = Var2)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") +
scale_fill_manual(values = c("red","green","yellow","black","white"),
guide_legend(title = "My_Title")) +
scale_y_continuous(breaks = (cumsum(df$Var2) -
df$Var2/2),
labels = df$Var1)
# reverse order appears
ggplot(df, aes(x = 1,
y = Var2,
fill = Var1)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") +
scale_fill_manual(values = c("red","green","yellow","black","white"),
guide_legend(title = "My_Title")) +
scale_y_continuous(breaks = (cumsum(df$Var2) -
df$Var2/2),
labels = df$Var1)
[2.2.0](https://blog.rstudio.org/2016/11/14/ggplot2-2-2-0/)のセクションのスタッキングバーのリリースノートを参照してください。 – Haboryme