干货分享 | R语言作图配色网站推荐
The following article is from 计量工作室 Author 计量工作室
R中的颜色设置(Ⅳ)-配色网站推荐
❝一般来说,R中一系列主题扩展包已经可以满足可视化的绝大多数需求。但是,对图形色彩要求较高的人群还是会选择自己设置颜色。以满足更加个性化的需求。
❞
这里将主要向大家推荐个人比较喜欢的配色网站,并结合上期ggpubr包未完成的内容展示其实战效果。
Color Hunt
首先推荐的配色网站是Color Hunt
颜色以四色为主,包括渐变色与随机色。特别值得称道的是,点击颜色标签可以自动复制到粘贴板,方便使用。点击♥号,自动收藏心仪配色,方便以后使用。
coolors.co
其次就是coolors.co这个网站,可以进行颜色筛选
点击「view」可以对已有配色进行颜色和顺序进行自定义,颜色标签可复制。
实战效果
经验累计密度函数
仍然使用上期构造的数据
library(ggpubr)
ggecdf(data,
x = c("high", "weight", "volume"),
combine = TRUE,
color = "country", palette = c("#721b65", "#b80d57", "#f8615a", "#7f78d2"))
Q-Q图
ggqqplot(data,
x = c("high", "weight", "volume"),
combine = T, color = "country", size = 0.8,
palette = c("#413c69", "#4a47a3", "#ad62aa", "#ffa372"),
add = "qqline", conf.int = T, conf.int.level = 0.95,
title = "QQ plot", facet.by = ".x.",
xlab = "", ylab = "")
配对样本比较
以中国为参考样本
ggpaired(data, x = "country", y = "volume",
color = "country",
palette = c("#BCE784", "#5DD39E", "#348AA7", "#525174"),
line.color = "gray", line.size = 0.4, combine = T,
facet.by = "rank", short.panel.labs = FALSE) +
stat_compare_means(label = "p.format", paired = TRUE, method = "t.test",
step.increase = 10, ref.group = "CH")
条线图
ggbarplot(data, x = "country", y = "weight", add = "mean_se",
fill = "sex",
palette = c("#525174", "#f78259"),
merge = T,
position = position_dodge(0.8)) +
stat_compare_means() +
stat_compare_means(aes(group = sex), label = "p.format", label.y = 6)
散点图
ggscatter(data, x = "high", y = "weight",
add = "reg.line",
conf.int = TRUE,
merge = T,
color = "country",
palette = c("#1B998B", "#2D3047", "#FFFD82", "#FF9B71"),
size = 1,
add.params = list(color = "#400082",
fill = "#f7beff")) +
stat_cor(method = "pearson", label.x = 1, label.y = 10)
show_point_shapes()
分段拟合绘图
ggscatter(data, x = "high", y = "weight",
add = "reg.line",
conf.int = TRUE,
merge = T,
color = "country",
palette = c("#1B998B", "#400082", "#d7385e", "#FF9B71"),
size = 1,
shape = "country") +
stat_cor(aes(group = country, color = country), method = "pearson", label.x = 1)
添加边际密度
ggscatter(data, x = "high", y = "weight",
add = "reg.line",
conf.int = TRUE,
merge = T,
color = "country",
palette = c("#1B998B", "#400082", "#d7385e", "#FF9B71"),
size = 1, rug = T,
shape = "country") +
stat_cor(aes(group = country, color = country), method = "pearson", label.x = 1)
绘制concentration ellipses
ggscatter(data, x = "high", y = "weight",
color = "country", shape = "country", sisize = 1,
ellipse = TRUE, palette = c("#084177", "#cd8d7b", "#f8dc88", "#be79df"),
ellipse.alpha = 0.5)
连接外边界
ggscatter(data, x = "high", y = "weight",
color = "country", shape = "country", sisize = 1,
ellipse = TRUE, palette = c("#084177", "#cd8d7b", "#f8dc88", "#be79df"),
ellipse.type = "convex",
ellipse.alpha = 0.5)
ggscatter(data, x = "high", y = "weight",
color = "country", shape = "country", sisize = 1,
ellipse = TRUE, palette = c("#084177", "#cd8d7b", "#f8dc88", "#be79df"),
ellipse.type = "norm",
ellipse.alpha = 0.6, mean.point = TRUE,
star.plot = TRUE, mean.point.size = 4)
棒状图
data1 <- data[which(data$high <= 1.5), ]
ggdotchart(data1, x = "name", y = "weight",
color = "rank",
palette = c("#084177", "#cd8d7b", "#f8dc88", "#be79df"),
sorting = "ascending",
add = "segments", dot.size = 2,
ggtheme = theme_pubr())
p <- ggdotchart(data1, x = "name", y = "weight",
color = "rank",
rotate = T,
palette = c("#084177", "#cd8d7b", "#f8dc88", "#be79df"),
sorting = "ascending",
add = "segments", dot.size = 5,
group = "rank",
label = round(data1$weight), # Add mpg values as dot labels
font.label = list(color = "white", size = 8,
vjust = 0.5),
ggtheme = theme_pubr())
ggpar(p, font.tickslab= c(8, "plain", "black"))
转载自计量工作室
经作者授权转载
文章仅代表作者观点,与本公众号无关,版权归原作者所有
原文标题:R中的颜色设置(Ⅳ)-配色网站推荐
排版:倪宁淇
责任编辑:黄莘绒
审编:鲁嘉颐
终审: 顾伟男 田巍 梁龙武
猜你喜欢
扫描二维码,关注我们
都看到这里了,点个【在看】再走呗~