其他分享
首页 > 其他分享> > R语言ggplot中的颜色

R语言ggplot中的颜色

作者:互联网

ggplot2分组时默认使用的颜色,可以从另一个hadley写的包,scales包中调用。这个包算是一个工具包,用于和hadley写的其他包配合使用,颜色是其中一部分。

library(scales)
show_col(hue_pal()(3))
# show_col(hue_pal(h = c(0, 360) + 15, c = 100, l = 65)(3)) # 和上面一样,默认设置

hue_pal函数的默认设置,其中h是色相,范围越大,相邻颜色之间差异越大;c是饱和度,值越大色彩越浓艳饱满;l是亮度,大亮小暗。

 

柱状图的颜色搭配:

colorbar <- function(values){
  groupbar + scale_fill_manual(values = values)
}

colorlist <- list(c("#8FBC94","#548687"),c("#4FB0C6","#4F86C6"),
                  c("#C65146","#EC6A5C"),c("#6E7783","#77AAAD"),
                  c("#e97f02","#f8ca00"),c("#3a5134","#4f953b"),
                  c("#99CCCC","#FFCC99"),c("#CC9999","#CCCC99"),
                  c("#0099CC","#FF6666"),c("#339966","#996699"),
                  c("#CC9966","#666666"),c("#336666","#CCCC33"),
                  brewer.pal(7, "Set1")[c(1,2)],brewer.pal(7, "Set1")[c(3,4)],
                  brewer.pal(7, "Set2")[c(5,6)],brewer.pal(7, "Set3")[c(6,7)],
                  brewer.pal(7, "Greens")[c(4,5)],brewer.pal(7, "Blues")[c(4,5)],
                  brewer.pal(7, "Oranges")[c(4,5)],brewer.pal(7, "Purples")[c(4,5)]
                  )

p <- marrangeGrob(lapply(colorlist, colorbar), nrow=0.5*length(colorlist), ncol=2, top="")
p

  另外两个比较常用的颜色设置:

来自于https://zhuanlan.zhihu.com/p/32746407

标签:hue,scale,默认设置,语言,scales,ggplot,颜色,pal
来源: https://www.cnblogs.com/qiniqnyang/p/11387054.html