Reputation: 452
I have two data vectors "Treatment" and "Radial.Error" given as follows (extract):
Treatment [1] random random random blocked random blocked random random random random blocked random random blocked [15] random random random blocked....
Radial.Error [1] 147.7693 149.3276 143.6707 209.3525 165.8738 185.6543 127.4760 119.7215 148.9003 114.5818 136.7522 114.1711 [13] 127.5891 202.8995 116.6201....
I want to generate boxplots as follows:
boxplot(Radial.Error ~ Treatment,main="Vergleich zwischen variabel und geblockt", ylab="Radialer Fehler (mm)", xlab="Posttest",col=(c("gold","lightblue")),)
However I want the group called "random" being labeled as "variabel" on the plot, and the group called "blocked" being labeled as "geblocket" - is there a way to change the labels of the boxplots via the boxplot function?
And if not, how can change the labels in the Treatment datavector (without having to do it one by one manually)?
Upvotes: 1
Views: 10616
Reputation: 4921
Data example (partly taken from your example):
Treatment <- c("random", "random", "random", "blocked", "random", "blocked", "random", "random", "random", "random", "blocked", "random", "random", "blocked", "random", "random", "random", "blocked")
Radial.Error <- c(147.7693, 149.3276, 143.6707, 209.3525, 165.8738, 185.6543, 127.4760, 119.7215, 148.9003, 114.5818, 136.7522, 114.1711, 127.5891, 202.8995, 116.6201, 115, 117, 119)
Boxplot
boxplot(Radial.Error ~ Treatment, names=c("variabel","geblockt"), main="Vergleich zwischen variabel und geblockt", ylab="Radialer Fehler (mm)", xlab="Posttest",col=(c("gold","lightblue")),)
Changing names in data frame
If you plan to make more plots with the new names, another alternative would be to change the names already in a data frame:
df<-data.frame(Treatment, Radial.Error)
names(df) <- c("variabel","geblockt")
Upvotes: 5