Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

r - Bar Chart with multiple labels ggplot2

I am trying to plot a bar chart that will show the name, year and percentage as labels. I have been able to get the percentage a label but not the name and year

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]
question from:https://stackoverflow.com/questions/65838967/bar-chart-with-multiple-labels-ggplot2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...