带有多个标签的条形图 ggplot2

时间:2021-01-22 03:37:32

标签: r ggplot2

我正在尝试绘制一个将名称、年份和百分比显示为标签的条形图。我已经能够获得标签的百分比,但不能获得名称和年份

df <- data.frame(
name = c('John','James','Kayden','Catherine','Joy','Paul','Elize'),
score = c(99,91,87,82,78,72,65),
group = c('a','a','a','b','b','b','b'),
year = c(2000,2001,2002,2003,2004,2005,2006)
)

 df$name <- as.factor(df$name)


 df$group <- as.factor(df$group)


 ggplot(df, aes(x = reorder(names, score), y = score)) +
 geom_col() +
 xlab("") +
  ylab("Percentage Score") +
 ggtitle("Test Score")+
 geom_text(aes(label = paste0(round(score*1,1),"%")), hjust = 2.5, colour = "Black") +
 scale_y_continuous(labels = function(x) paste0(x*1, "%"))+
  coord_flip()[enter image description here][1]

0 个答案:

没有答案