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

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

  • scale_fill_manual(): 填充色
  • scale_color_manual():轮廓色,如点线

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

posted @ 2019-08-21 09:59  qinqinyang  阅读(6612)  评论(0编辑  收藏  举报