3

I'm trying to visualize some data sorted by two variables: Year and Students. Here is my data:

graphos <- data.frame(c(2007,2007,2007,2008,2008,2008,2009,2009,2009),
                      c("A","B","C","A","E","B","D","B","A"),
                      c(52080,49426,42522,53124,50784,45920,55971,52216,49850))

names(graphos) <- c("Year","Classroom","Students")

graph2 <- ggplot(graphos, aes(fill=Classroom, y=Students, x=Year)) + 
  geom_bar(position="dodge", stat="identity", color='black')

graph2

And here is the result:

I've tried the option of fill=reorder, but it doesn't work either:

graph2 <- ggplot(graphos, aes(fill=reorder(Classroom, -Students), y=Students, x=Year)) + 
  geom_bar(position="dodge", stat="identity", color='black')

graph2

What I would need is to sort by both year (ascending) and students (descending), but my graph only order by year. Can you help me?

Thanks!

hpesoj626
  • 3,529
  • 1
  • 17
  • 25

0 Answers0