李家翔 2019-03-21
参考 github
library(wesanderson)
names(wes_palettes)
## [1] "BottleRocket1" "BottleRocket2" "Rushmore1" "Rushmore"
## [5] "Royal1" "Royal2" "Zissou1" "Darjeeling1"
## [9] "Darjeeling2" "Chevalier1" "FantasticFox1" "Moonrise1"
## [13] "Moonrise2" "Moonrise3" "Cavalcanti1" "GrandBudapest1"
## [17] "GrandBudapest2" "IsleofDogs1" "IsleofDogs2"
library(wesanderson)
library(magrittr)
wes_palette("Royal1") %>% length
## [1] 4
suppressMessages(library(tidyverse))
mtcars %>%
ggplot(aes(factor(cyl), fill=factor(vs))) +
geom_bar() +
scale_fill_manual(values = wes_palette("Royal1"))
但是不支持 NSE,已经提交了 Github Issue 35
mtcars %>%
rownames_to_column('name') %>%
ggplot(aes(name,mpg)) +
coord_flip() +
geom_col(aes(fill = name)) ->
p_pre_fill
p_pre_fill +
scale_fill_brewer(palette = "Spectral")
## Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Spectral is 11
## Returning the palette you asked for with that many colors
# 光谱
显然也是不够的。
但是不是很清楚如何确定有几个分类,已经提交 RStudio Community。 参考 R color cheatsheet
library(RColorBrewer)
display.brewer.all()
brewer.pal.info %>%
rownames_to_column('color') %>%
ggplot(aes(fct_reorder(color,maxcolors), maxcolors)) +
geom_col() +
coord_flip()
p_pre_fill +
scale_fill_hue(c=45, l=80)
但是和默认的差不多,不是很美观。
这项配色是根据色盲研究提出的,为了更好地打印和服务色盲人群。
library(ggthemes)
palette_pander(100) %>%
unique() %>%
print %>%
length
## [1] "#56B4E9" "#009E73" "#F0E442" "#0072B2" "#D55E00" "#CC79A7" "#999999"
## [8] "#E69F00"
## [1] 8
但是似乎颜色不够。
mtcars %>%
head(8) %>%
rownames_to_column('name') %>%
ggplot(aes(name,mpg)) +
coord_flip() +
geom_col(aes(fill = name)) +
scale_fill_manual(values = palette_pander(nrow(mtcars)))
参考 Github Pages
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am)
p + theme_excel_new() + scale_colour_excel_new()