前言
前段时间做分析有伙计觉得原文章绘图颜色太low,提到要眼前一亮。为调色盘而烦恼?笔者冲浪冲到两个R包,ggGenshin
&Genshinpalette
,信仰拉满,其实关于配色铁粉肯定有自己配一套调色盘,这里分享的是现成打包好的配色,直接使用,这把高端局
ggGenshin
安装R包:
devtools::install_github("RestlessTail/ggGenshin")
library(ggGenshin)
查看一下“阵容”
ggGenshin::keys()
# key.name en.fullname cn.fullname
# 1 albedo Albedo 阿贝多
# 2 alhaitham Alhaitham 艾尔海森
# 3 ayaka Kamizato Ayaka 神里绫华
# 4 bennett Bennett 班尼特
# 5 collei Collei 柯莱
# 6 diona Diona 迪奥娜
# 7 dori Dori 多莉
# 8 faruzan Faruzan 珐露珊
# 9 ganyu Ganyu 甘雨
# 10 itto Arataki Itto 荒泷一斗
# 11 jean Jean 琴
# 12 jin Yun Jin 云堇
# 13 kazuha Kaedehara Kazuha 枫原万叶
# 14 keqing Keqing 刻晴
# 15 klee Klee 可莉
# 16 kokomi Sangonomiya Kokomi 珊瑚宫心海
# 17 miko Yae Miko 八重神子
# 18 nahida Nahida 纳西妲
# 19 nilou Nilou 妮露
# 20 noelle Noelle 诺艾尔
# 21 razor Razor 雷泽
# 22 sayu Sayu 早柚
# 23 shenhe Shenhe 申鹤
# 24 shogun Raiden Shogun 雷电将军
# 25 sucrose Sucrose 砂糖
# 26 tao Hu Tao 胡桃
# 27 tighnari Tighnari 提纳里
# 28 venti Venti 温迪
# 29 xiangling Xiangling 香菱
# 30 xiao Xiao 魈
# 31 yoimiya Yoimiya 宵宫
# 32 zhongli Zhongli 钟离
这边随便造了个数据框,5个基因,10个分组,每组15个样本,即150x5
的矩阵。笔者不玩这游戏,有点脸盲,任意挑了几个配色结果出来,请选择你的“英雄”:
set.seed(123)
# 创建数据框
df <- data.frame(
group = rep(letters[1:10], each = 15), # 这里使用letters[1:10]来得到a-j
gene1 = rnorm(150),
gene2 = rnorm(150),
gene3 = rnorm(150),
gene4 = rnorm(150),
gene5 = rnorm(150)
)
library(tidyverse)
# 计算每个组和基因的均值
df_melted <- df %>%
gather(key="gene", value="expression", -group) %>%
group_by(group, gene) %>%
summarise(mean_expression=mean(expression))
ggplot(df_melted, aes(x=gene, y=mean_expression, fill=group)) +
geom_bar(stat="identity", position="dodge") +
ggtitle("Mean Expression Levels across Genes and Groups") +
xlab("Gene") +
ylab("Mean Expression Level") +
theme_minimal() +
scale_fill_albedo()
plot_list <- lapply(1:length(ggGenshin::keys()$key.name), function(i) {
key <- ggGenshin::keys()$key.name[i]
scale_function_name <- paste0("ggGenshin::scale_fill_", key)
scale_function <- eval(parse(text=scale_function_name))
p <- ggplot(df_melted, aes(x=gene, y=mean_expression, fill=group)) +
geom_bar(stat="identity", position="dodge") +
ylab("Mean Expression Level") +
theme_minimal() +
theme(axis.text.x=element_blank(), axis.title.x=element_blank()) +
scale_function()
# 只在第一个图上添加标题
if (i == 1) {
p <- p + ggtitle("Mean Expression Levels")
}
return(p)
})
library(gridExtra)
# 定义每个页面上的图的数量
plots_per_page <- 4
num_pages <- ceiling(length(plot_list) / plots_per_page)
pdf("output_plots.pdf",width = 15,height = 10)
for (page in 1:num_pages) {
start_idx <- (page - 1) * plots_per_page + 1
end_idx <- min(page * plots_per_page, length(plot_list))
grid.arrange(grobs = plot_list[start_idx:end_idx], ncol=2, nrow=2)
}
dev.off()
1~4
5~8
29~32
21~24
29~32
Genshinpalette
安装R包
remotes::install_github("Schwarzeneggerjune/Genshinpalette",force = T)
library(Genshinpalette)
查看“阵容”
好像大差不差
char_name=get_character_name(Country = "All")#Country原神中全部国家
head(char_name,67)
# ALBEDO ALOY AMBER BARBARA BENNETT
# "阿贝多" "埃洛伊" "安柏" "芭芭拉" "班尼特"
# DIONA DILUC FISCHL KAEYA KLEE
# "迪奥娜" "迪卢克" "菲谢尔" "凯亚" "可莉"
# KONG RAZOR LISA ROSARIA MONA
# "空" "雷泽" "丽莎" "罗莎莉亚" "莫娜"
# NOELLE PIMON JEAN SUCROSE VENTI
# "诺艾尔" "派蒙" "琴" "砂糖" "温蒂"
# YING EULA MIKA BEIDOU TARTAGLIA
# "荧" "优菈" "米卡" "北斗" "达达利亚"
# GANYU HUTAO KEQING NINGGUANG QIQI
# "甘雨" "胡桃" "刻晴" "凝光" "七七"
# SHENHE XIANGLING XIAO XINYAN XINGQIU
# "申鹤" "香菱" "魈" "辛焱" "行秋"
# YANFEI YAOYAO YELAN YUNJIN ZHONGLI
# "烟绯" "瑶瑶" "夜兰" "云堇" "钟离"
# CHONGYUN YAEMIKO KAEDEHARAKAZUHA ARATAKIITTO KUJOSARA
# "重云" "八重神子" "枫原万叶" "荒泷一斗" "九条裟罗"
# RAIDENSHOGUN SHIKANOINHEIZOU SANGONOMIIYAKOKOMI KAMISATOAYAKA KAMISATOAYATO
# "雷电将军" "鹿野院平藏" "珊瑚宫心海" "神里绫华" "神里绫人"
# THOMA GOROU YOIMIYA SAYU KUKISHINOBU
# "托马" "五郎" "宵宫" "早柚" "久岐忍"
# ALHAITHAM DORI FARUZAN CANDACE COLLEI
# "艾尔海森" "多莉" "珐露珊" "坎蒂丝" "柯莱"
# LAYLA WANDERER NAHIDA NILOU CYNO
# "莱依垃" "流浪者" "纳西妲" "妮露" "赛诺"
# TIGHNARI DEHYA
# "提纳里" "迪希雅"
用diamonds数据集,开整吧
library(ggplot2)
data("diamonds")
ggplot(
subset(diamonds, carat >= 2.2),
aes(x = table, y = price, colour = cut)
) +
geom_point(alpha = 0.9) +
geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1) +
theme_bw()+
scale_color_manual(values = Genshinpalette('WANDERER'))
调色板都已经整理好的,可以直接调用:
Genshinpalette('RAIDENSHOGUN',#角色名称
20)#所需颜色个数,默认为6
# [1] "#EADDF2" "#DCCCED" "#CEBBE9" "#C3ABE6" "#BDA0E4" "#B794E1" "#AC89CF" "#9C7CB0" "#8D7091"
# [10] "#8970A3" "#8873BC" "#8471CD" "#7558A7" "#654081" "#59326E" "#513372" "#493477" "#3C2F6F"
# [19] "#2D2762" "#1F1F56"
display_colors('RAIDENSHOGUN')
小总结
有时候文章投不出去万一是图不够好看,文章投出去分不高万一是配色不够艳,这把高端局,Genshin
的配色丝毫不输于发表级正刊SCI的调色板,冲吧战士们,喜欢点个赞收藏一手
笔者不玩原神,各位佬们勿cue