I have 6 data columns, 100 rows each, loaded into mydata. I want to create a 6-column boxplot, one plot for each row. I am using the command
boxplot(mydata,main="Performance over 100 trials", xlab="N", ylab = "ms")
This creates the correct boxplot. However, it labels the variables "V1" through "V6" and I want to label them otherwise. I saw a suggestion that the labels should be the first line of my data file, but that doesn't seem to work. How can I rename these values?
boxplot has a names argument. Compare the output of the following example:
set.seed(1)
temp <- as.data.frame(matrix(rnorm(100), ncol = 5))
boxplot(temp)

boxplot(temp, names = c("A", "B", "C", "D", "E"))

You can use the colnames() command.
colnames(mydata)[1] <- "first column name"
colnames(mydata)[2] <- "second column name"
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With