R中的条形图传说

时间:2018-05-31 04:18:21

标签: r

我有这样的表中的数据 I need a barplot for the same in R.。所以我想要的是在x轴上,High_score,Medium_score和Low_score应该用平均值,最大值和标准差(除了= TRUE之外)用三种不同颜色绘制,平均值,最大值和SD值应该在图例中表示。有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

library(tidyverse)

df <- data_frame(
  "stat" = c("mean", "max", "sd"),
  "High_score" = c(55.6, 60, 5.1),
  "Medium_score" = c(40, 45, 4.3),
  "Low_score" = c(20, 28, 3.8)
)

df <- gather(df, key = score, value = value, -stat)

ggplot(df, aes(x = score, y = value, fill = stat)) +
  geom_col(position = "dodge")

enter image description here