如何在R中为箱线图指定颜色?只能使用base R
我在尝试为R中的箱线图指定颜色时遇到问题。这是我尝试运行代码时的代码和输出。真的不知道该怎么办如何在R中为箱线图指定颜色?只能使用base R,r,plot,graph,colors,boxplot,R,Plot,Graph,Colors,Boxplot,我在尝试为R中的箱线图指定颜色时遇到问题。这是我尝试运行代码时的代码和输出。真的不知道该怎么办 region1<-c("North-Apulia","Calabria","South-Apulia","Sicily") region2<-c("Inland-Sardinia,","Coast-Sardinia") region3<-c("Umbria
region1<-c("North-Apulia","Calabria","South-Apulia","Sicily")
region2<-c("Inland-Sardinia,","Coast-Sardinia")
region3<-c("Umbria","East-Liguria","West-Liguria")
# c - Boxplots
mycolors<-ifelse(levels(betterolivelabel)==region1,col="red",
ifelse(levels(betterolivelabel)==region2,col="blue",
ifelse(levels(betterolivelabel)==region3, col="green")))```
```Error in ifelse(levels(betterolivelabel) == region1, col = "red", ifelse(levels(betterolivelabel) == :
unused argument (col = "red")```
>
region1如果要比较多个值,请使用%
中的%。此外,如果不满足任何条件,则需要提供最终值
lvls <- levels(betterolivelabel)
mycolors<-ifelse(lvls %in% region1,"red",
ifelse(lvls %in% region2,"blue",
ifelse(lvls %in% region3, "green", "black")))
lvls当
library(dplyr)
lvls <- levels(betterolivelabel)
mycolors <- case_when(lvls %in% region1 ~ "red",
lvls %in% region2 ~ "blue",
lvls %in% region3 ~ "green",
TRUE ~ "black")
库(dplyr)
lvls