[R] How to color boxplots with respect to the variable names

Neha gupta neh@@bo|ogn@90 @end|ng |rom gm@||@com
Sun May 29 20:46:07 CEST 2022


I have the following data and I need to use a boxplot which displays the
variables (RF, Ranger, SVM, KNN) with one color, variables (RF_boot,
Ranger_boot, SVM_boot, KNN_boot) with another color and the variables
(RF_LOO, SVM_LOO, Ranger_LOO, KNN_LOO) with another color.

How can I do that? Currently, I am using the base boxplot which displays
them in one color. I know it will be more easily achieved with ggplot but I
have no experience/knowledge with it.

RF= c(4.7, 1.52, 1.46, 4.5, 0.62, 1.12)
RF_LOO= c(5.2, 1.52, 1.44, 4.3, 0.64, 1.11)
RF_boot= c(5.8, 1.5, 1.23, 4.3, 0.64, 1.12)
Ranger= c(4.5, 1.57, 1.25, 3.75, 0.56, 1.09)
Ranger_LOO= c(5, 1.56, 1.35, 3.7, 0.6, 1.0)
Ranger_boot= c(4.2, 1.53, 1.12, 3.7, 0.63, 1.1)
SVM= c(3.51, 1.34, 0.62, 1.45, 0.5, 1.06)
SVM_LOO= c(3.6, 1.33, 0.33, 1.4, 0.41, 1.1)
SVM_boot= c(3.75, 1.35, 0.58, 1.4, 0.4, 1.0)
KNN= c(2.85, 1.35, 0.25, 1.76, 0.43, 1.25)
KNN_LOO= c(2.85, 1.34, 0.375, 1.75, 0.44, 1.27)
KNN_boot= c(2.75, 1.35, 0.375, 1.75, 0.45, 1.27)

My base boxplot is here

colors = rep("blue",12)
at.x <- seq(1,by=.4, length.out = 10)
boxplot(RF, RF_LOO, RF_boot, Ranger, Ranger_LOO, Ranger_boot, SVM, SVM_LOO,
SVM_boot,
        KNN, KNN_LOO, KNN_boot, range = 0, col=colors, names= c("RF",
"RF_LOO", "RF_boot",
        "Ranger", "Ranger_LOO", "Ranger_boot", "SVM", "SVM_LOO", "SVM_boot",
        "KNN", "KNN_LOO",
"KNN_boot"),las=2,boxwex=0.5,outline=FALSE,cex.axis=0.8, main="Consistency
of the 100% features ")

	[[alternative HTML version deleted]]



More information about the R-help mailing list