我需要做一个"堆叠条形图"使用ggplot2 FOE以下数据(类似于下面的图片)
stacked bar plot- what i needed 说
State <- c("All India", "Arunachal Pradesh", "Gujarat", "Jammu & Kashmir", "Madhya Pradesh", "Maharashtra", "Meghalaya", "Mizoram", "Orissa", "Punjab", "Tamil Nadu", "Uttar Pradesh", "West Bengal")
Mean <- c(217, 227, 214, 217, 217, 204, 209, 215, 223, 243, 220, 230, 210)
Percentile_5th <- c(163, 193, 162, 185, 177, 146, 169, 173, 167, 183, 156, 163, 170)
Percentile_95th <- c(271, 262, 265, 249, 258, 261, 249, 257, 280, 302, 284, 297, 249)
我需要为所有州
我还需要go 任何两个邦("全印度","旁遮普")
我已经try 使用以下代码为两个州创建了它
data <- data.frame(
State = rep(c("All India", "Punjab" ), each = 3),
Metric = rep(c("5th Percentile", "Mean", "95th Percentile"), 2),
Value = c(163, 217, 271, 183, 243, 302) # 5th P, Mean increment, 95th P increment for each state
)
ggplot(data, aes(x = State, y = Value, fill = Metric)) +
geom_bar(stat = "identity") +
geom_text(aes(label = Value), position = position_stack(vjust = 0.5)) +
scale_fill_manual(values = c("5th Percentile" = "orange", "Mean" = "blue", "95th Percentile" = "green")) +
labs(title = "Stacked Bar Plot for All India and Punjab",
x = "State",
y = "Values",
fill = "Metric") +
theme_minimal()
我收到的输出是
我需要的曲线图(如我前面所说)是条形图底部的第五个百分位数,条形图中间的下一个平均值,以及条形图顶部的第95个百分位数.但它不是这样给予的.此外,我需要为所有的州做一个类似的情节.请帮帮我