達成したいことに非常に近づいていますが、グラフに最後の仕上げを追加する方法が見つかりません。これが私が持っているもので、グラフを生成するための foo データとコードがあります。
reshape パッケージからの融解データ:
mdf <- structure(list(v1 = structure(c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 2L, 1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L), .Label = c("ind1",
"ind10", "ind2", "ind3", "ind4", "ind5", "ind6", "ind7", "ind8",
"ind9"), class = "factor"), v2 = c(2, 3, 1, 2, 2, 2, 3, 1, 4,
4, 2, 3, 1, 2, 2, 2, 3, 1, 4, 4), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("v3", "v4"), class = "factor"), value = c(0.8,
0.7, 0.7, 0.6, 0.4, 0.3, 0.2, 0.3, 0.9, 0.8, 0.2, 0.3, 0.3, 0.4,
0.6, 0.7, 0.8, 0.7, 0.1, 0.2)), .Names = c("v1", "v2", "variable",
"value"), row.names = c(NA, -20L), class = "data.frame")
グラフ:
library(ggplot2)
ggplot(mdf,aes(x=reorder(v1,v2),y=value,fill=factor(v2))) + geom_bar(stat="identity",color="black")
ここで、各バーのトップ スタックに異なる色を付ける必要があります。透明度やイベント カラーをすべてトップ スタック グレーにするなどです。データセットの現在の構造でそれを行うことはできますか、それともデータを別の方法で再形成することを検討する必要がありますか?
ありがとう
編集: Didzis が提供するコードからの出力グラフ: