Randy Minder Randy Minder - 1 year ago 85
R Question

BoxPlots - How to label the bars?

I have a data frame that looks like this:

fmonth X_state totalDays
<fctr> <fctr> <dbl>
1 January Alabama 11.407433
2 January Mississippi 10.469454
3 January Arkansas 10.436242
4 January Tennessee 10.374277
5 January Kentucky 10.124040
6 January Louisiana 9.417397
7 January New Mexico 9.199898
8 January West Virginia 9.167906
9 January Arizona 8.992925
10 January South Carolina 8.942059
# ... with 43 more rows

I'd like to create a box plot that looks something like this:

enter image description here

I'd like the total days on the Y axis and the states along the X axis. I can achieve this with the following R code:

barplot(januaryData$totalDays, main="January", xlab="State", ylab="Total Days" )

However, what I'm not getting are the state names at the bottom of each bar, and I'm not sure how to go about getting the state names to appear. By the way, I plan to reduce the number of states shown here to about 10, so the bar plot, eventually, won't look so cluttered.

Answer Source

Simple as barplot(..., names.arg = januaryData$X_state)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download