0

I am trying to create a box plot of the Baltimorecity Salaries open data:

enter image description here

> par(mar=c(16,4,1,1)) 
> boxplot(mydata$GROSSPAY ~ mydata$AGENCY, las=2)

enter image description here

I would like to display the boxes in order of of the total GROSSPAY of the AGENCY.

Is this possible with R? If so, how?


As this question was closed, I'm pasting an answer here:

mydata <- mydata[ ! is.na(mydata$GROSSPAY),  ]
mydata$AGENCY <- with(mydata, reorder(AGENCY, GROSSPAY, sum))

par(las=2)
par(mar=c(16,4,1,1))
boxplot(mydata$GROSSPAY ~ mydata$AGENCY)
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • Yes. Is there anything you've already tried yourself? – Heroka Sep 03 '15 at 15:42
  • No. I have a complete mental block how to move forward on this. – Chris Snow Sep 03 '15 at 15:51
  • If you break it down, you have two things to do. First, calculate the GROSSPAY per AGENCY, and then order the boxplots by that total. For the first one, you could use aggregate, plyr or dplyr, whatever you're comfortable with. And for the second part two links were supplied. – Heroka Sep 03 '15 at 15:57
  • @Heroka - thanks, that helped a lot. I've updated the question with the answer. – Chris Snow Sep 03 '15 at 16:33
  • Well done! Glad I could help you go past your mental block. – Heroka Sep 03 '15 at 16:58

0 Answers0