2

I have a table with a header that seems to be ruining my plots.

        | Header2 | 
--------+---------+
a       | 1       | 
b       | 5       |
c       | 7       |

I want to barplot the x and y values against each other, and I can, but it does not print out the values "a,b,c" on the x-axis

And when I run:

barplot(xyz.rf$importance[order(xyz.rf$importance, decreasing = TRUE)], ylim=c(0,40) las=2)

It does not print out the x values on the graph

xyz.rf$importance looks like this:

           MeanDecreaseGini
a            25.803414
b            20.671604
c            14.043655
d            20.307379
e            27.805377
f            11.427971
g            14.104592

How do I fix this?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Dr.Doofus
  • 55
  • 1
  • 1
  • 10

1 Answers1

2

We could transpose the object

barplot(t(df1), ylim=c(0,40), las=2)

enter image description here

where,

df <- xyz.rf$importance
df1 <- df[order(df[, "MeanDecreaseGini"], decreasing = TRUE), , drop = FALSE]
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    That did it! Thank you. Why does this work exactly, but my method above didn't work? – Dr.Doofus May 25 '18 at 05:55
  • 2
    @H.Ozdil According to `barplot` `If ‘height’ is a matrix and ‘beside’ is ‘FALSE’ then each bar of the plot corresponds to a column of ‘height’, with the values in the column giving the heights of stacked sub-bars making up the bar.` If we don't transpose, then there is only a single column and barplot works on `vector` and `matrix`. I am not sure whether you have a matrix or data.frame. Assuming that you had a matrix, the 'x' axis label will be 'MeanDecreasingGini' – akrun May 25 '18 at 05:58