-1

I making a boxplot, where I've named the x/y-axis something. The problem is that on the x-axis there is nothing besides the label I've made. I expected it that there would be 3, 5, 10 & 17 under the boxes.

enter image description here

I've used this command to make the boxplot:

boxplot(HE.JF$Q[HE.JF$houseId==3], 
        HE.JF$Q[HE.JF$houseId==5], 
        HE.JF$Q[HE.JF$houseId==10], 
        HE.JF$Q[HE.JF$houseId==17], 
        col = c("red", "blue", "yellow", "pink"), 
        ylab ="Heat consumption (kW)", xlab="House")
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
Bob
  • 3
  • 1
  • 6

1 Answers1

1

R does not print 3, 5, 10, 17 beneath the box plots, because it doesn't know the houseID.

This happens because you don't plot directly from HE.JF$Q (which you can do by use of a formula, as pointed out by @Roland in a comment above). Instead what you do is to plot four individual extracts from HE.JF$Q (like HE.JF$Q[HE.JF$houseId==3]).

If this is how you want to do it, you can add the names-argument to boxplot().

boxplot(HE.JF$Q[HE.JF$houseId==3], 
        HE.JF$Q[HE.JF$houseId==5], 
        HE.JF$Q[HE.JF$houseId==10], 
        HE.JF$Q[HE.JF$houseId==17], 
        col = c("red", "blue", "yellow", "pink"), 
        ylab ="Heat consumption (kW)", xlab="House", 
        names = c("3","5","10","17"))
Community
  • 1
  • 1
harre
  • 7,081
  • 2
  • 16
  • 28