方式1
rm(list=ls())
ncolors =5
data = data.frame(value=rep(5,ncolors)) # 一定要加入这个结果的
colors = colorRampPalette(c("blue","red"))(nrow(data))
#colors = c('#0000FF','#3F00BF','#7F007F','#BF003F','#FF0000')
barplot(data$value,col=colors,names.arg = colors)
# 但是这种对于10类就不适用了
结果如下
方式2
library(paletteer)
# 根据需求调颜色
paletteer_d("Polychrome::kelly", n = 22)
方式3
col.set.update = paletteer_d("Polychrome::kelly", n = 22)
# col.set.update <- c("#c10023", "#008e17", "#fb8500", "#f60000", "#FE0092", "#bc9000","#4ffc00", "#00bcac", "#0099cc",
# "#D35400", "#00eefd", "#cf6bd6", "#99cc00", "#aa00ff", "#ff00ff", "#0053c8",
# "#f2a287","#ffb3ff", "#800000", "#77a7b7", "#00896e", "#00cc99", "#007CC8")
image(1:length(col.set.update),1, as.matrix(1:length(col.set.update)),col=col.set.update,ylab="",xlab="",axes=F)
axis(3,at=seq(1:length(col.set.update)),labels=col.set.update,las=2,lwd=0)
col.set.update <- c("#c10023", "#008e17", "#fb8500", "#f60000", "#FE0092", "#bc9000","#4ffc00", "#00bcac", "#0099cc",
"#D35400", "#00eefd", "#cf6bd6", "#99cc00", "#aa00ff", "#ff00ff", "#0053c8",
"#f2a287","#ffb3ff", "#800000", "#77a7b7", "#00896e", "#00cc99", "#007CC8")
image(1:length(col.set.update),1, as.matrix(1:length(col.set.update)),col=col.set.update,ylab="",xlab="",axes=F)
axis(3,at=seq(1:length(col.set.update)),labels=col.set.update,las=2,lwd=0)