我正在尝试创建一个自定义 ggplot 主题,如下所示:
library(data.table)
library(tidyverse)
# On definit les couleurs
CouleurTitre = "#006CE5" #Bleu titre
Couleur_QuadrillagePrimaire ="#B9CDE5"
Couleur01 = rgb(000,112,192, maxColorValue = 255) # Bleu
Couleur02 = rgb(255,102,000, maxColorValue = 255) # Orange
Couleur03 = rgb(000,176,080, maxColorValue = 255) # Vert
Couleur04 = rgb(255,204,000, maxColorValue = 255) # Jaune d'or
Couleur05 = rgb(192,000,000, maxColorValue = 255) # Rouge
Couleur06 = rgb(128,128,128, maxColorValue = 255) # Gris
Couleur07 = rgb(000,176,240, maxColorValue = 255) # Bleu ciel
Couleur08 = rgb(102,255,051, maxColorValue = 255) # Vert pomme
Couleur09 = rgb(102,255,051, maxColorValue = 255) # Violet
Couleur10 = rgb(247,150,070, maxColorValue = 255) # Saumon
Palette_Test = sapply((sprintf("Couleur%02d", 1:10)),function(x) get(x),USE.NAMES = FALSE)
# Theme Tresor
Attempted_Theme <- theme_classic()+
theme(plot.title = element_text(size=18, face="bold", hjust=0.5, color=CouleurTitre))+
theme(panel.grid.major = element_line(colour=Couleur_QuadrillagePrimaire, size=0.5, lineend = "butt"))+
theme(axis.title.x = element_blank(),axis.title.y = element_blank())+
theme(panel.background = element_rect(colour = "Black",size=1.5)) +
theme(legend.title=element_blank(),legend.position="bottom")+
theme(axis.ticks=element_blank())
ggtest <- function(...){
ggplot(...) +
Attempted_Theme +
scale_colour_manual(values =Palette_Test)
}
使用的数据如下:
MWE <- as.data.table(ggplot2::economics) %>%
melt(.,id="date")
因此,我编写了几种颜色,打算在 ggplot2 中用于大多数用途。但我可能没有找到最好的选择scale_coulour_manual,因为它不会改变真正的基本颜色线:
我的第一种颜色是蓝色,我可以通过这种方式获得所需的输出:
ggtest(data=MWE[variable == "pce",],
aes(x=date,y=value,colour=variable))+
geom_line(size=1)
但是,如果我理想情况下希望不指定颜色的标准行为aes也是蓝色,而现在它是黑色
ggtest(data=MWE[variable == "pce",],
aes(x=date,y=value))+
geom_line(size=1)


