美文网首页
分享我常用的一些绘图颜色(16进制颜色码)

分享我常用的一些绘图颜色(16进制颜色码)

作者: R语言与SPSS学习笔记 | 来源:发表于2021-05-02 11:44 被阅读0次

在作图的时候总是担心颜色不好看?来看看我常用的个人觉得蛮好看的颜色, 共有16种颜色,分别是:

"#3B99D4", "#8ED14B", "#F06B49","#ECC2F1", "#82C7C3", "#E3698A","#1776EB", "#F5B2AC", "#533085","#89363A","#19413E", "#D92B45", "#60C9FF", "#1B9F2E", "#BA217D", "#076B82"

首先把颜色弄成表格的样子:

my_table <- structure(list(V1 = c("#3B99D4", "#8ED14B", "#F06B49","#ECC2F1", "#82C7C3", "#E3698A","#1776EB", "#F5B2AC"), 
V2 = c( "#533085","#89363A","#19413E", "#D92B45", "#60C9FF", "#1B9F2E", "#BA217D", "#076B82")), class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8"))

将上述各种颜色展现出来:

library(ggplot2)
library(dplyr)
library(tidyr)

my_table %>%
tibble::rownames_to_column() %>%
mutate(rowname = as.numeric(rowname)) %>%
pivot_longer(-1) %>%
ggplot(aes(x = name, y = rowname, fill = value)) +
geom_tile(color = "gray50") +
scale_fill_identity() +
scale_x_discrete(position = "top") +
scale_y_reverse(breaks = seq(nrow(my_table))) +
coord_equal()

这样就可以在作图的时候直接选喜欢的颜色了,比如我现在要做一个饼图,我想选择的第一列1-6行的颜色(查看上面的my_table即可知道颜色代码)

value = rep(10,times=6)#数据准备
names = c("A", "B", "C", "D","E", "F")#命名
cols = c("#3B99D4", "#8ED14B", "#F06B49","#ECC2F1", "#82C7C3", "#E3698A")# 涂色
pie(value, labels=names, col=cols)# 绘图

由于不是同步更新,更多内容请关注我们的微信公众号:R语言与SPSS学习笔记

相关文章

网友评论

      本文标题:分享我常用的一些绘图颜色(16进制颜色码)

      本文链接:https://www.haomeiwen.com/subject/qfetdltx.html