本文介绍了模拟ggplot2默认调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我可以使用什么函数来模拟ggplot2的默认调色板以获得所需数量的颜色。例如,输入3会产生一个带有以下颜色的HEX颜色的字符向量: 解决方案这只是色轮周围的等间距色调,从15开始: gg_color_hue hues = seq(15,375,length = n + 1) hcl h = hues,l = 65,c = 100)[b] b $ b >例如: n = 4 cols = gg_color_hue(n) dev .new(width = 4,height = 4) plot(1:n,pch = 16,cex = 2,col = cols) What function can I use to emulate ggplot2's default color palette for a desired number of colors. For example, an input of 3 would produce a character vector of HEX colors with these colors: 解决方案 It is just equally spaced hues around the color wheel, starting from 15:gg_color_hue <- function(n) { hues = seq(15, 375, length = n + 1) hcl(h = hues, l = 65, c = 100)[1:n]}For example:n = 4cols = gg_color_hue(n)dev.new(width = 4, height = 4)plot(1:n, pch = 16, cex = 2, col = cols) 这篇关于模拟ggplot2默认调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!