Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Labeling columns in R

Tags:

r

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?

like image 329
Eric Tressler Avatar asked Feb 01 '26 21:02

Eric Tressler


2 Answers

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)

enter image description here

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

enter image description here

like image 135
A5C1D2H2I1M1N2O1R2T1 Avatar answered Feb 03 '26 12:02

A5C1D2H2I1M1N2O1R2T1


You can use the colnames() command.

colnames(mydata)[1] <- "first column name"
colnames(mydata)[2] <- "second column name"
...
like image 36
EarlGrey Avatar answered Feb 03 '26 13:02

EarlGrey