重複の可能性:
ggplot2 の積み上げ棒グラフにデータ値を表示する
私は次のggplotを持っています
dt <- structure(list(Age.group = structure(1:5, .Label = c("0-29 yrs", "30-49 yrs", "50-64 yrs", "65-79 yrs", "80+ years"), class = "factor"), Rx.Brufen = c(4.91767279891635, 24.849329416471, 39.384529665324, 42.0512030516413, 45.0282816501013), Brufen.C.I = c(9.49857407873833, 10.4942035949849, 11.0935906177108, 16.7322917304551, 18.5232702433842 ), Brufen.declined = c(1.25219908256281, 1.1156980249761, 1.18510539437499, 0.73845826559561, 1.00121613129538)), .Names = c("Age.group", "Rx.Brufen", "Brufen.C.I", "Brufen.declined"), row.names = c(NA, -5L), class = "data.frame")
dt.m <- melt(dt, 1)
colnames(dt.m)[2] <- "Rx"
colnames(dt.m)[3] <- "Proportion"
ggplot(dt.m, aes(x=Age.group,y=Proportion, fill=Rx)) +
geom_bar() +
labs(x="Age Group", y="Proportion %",fill = "") +
theme(legend.position=c(.5, .9), legend.direction = "horizontal" ) +
ylim(c(0,100))
実際の値をパーセンテージとしてプロットしたいと思います(緑と赤のバーはバーの内側、青のバーは内側に収まらないため、すぐ上)。誰かがこれを達成する方法をアドバイスできますか?