Wes Anderson调色盘的R实现

绘制渐变图时,有一些调色板可以直接使用,这里介绍Wes Anderson调色盘,以及在R中的实现

devtools::install_github("karthik/wesanderson")
library(wesanderson)
names(wes_palettes)
##  [1] "BottleRocket1"  "BottleRocket2"  "Rushmore1"      "Royal1"        
##  [5] "Royal2"         "Zissou1"        "Darjeeling1"    "Darjeeling2"   
##  [9] "Chevalier1"     "FantasticFox1"  "Moonrise1"      "Moonrise2"     
## [13] "Moonrise3"      "Cavalcanti1"    "GrandBudapest1" "GrandBudapest2"

产生颜色向量的主要函数为

wes_palette(name, n, type = c("discrete", "continuous"))

  • name: 调色名称
  • n: 颜色数据,大部分只有4-5个颜色
  • type:  “continuous” 或者 “discrete”.

library("ggplot2")
# Box plot
bp <- ggplot(iris, aes(Species, Sepal.Length)) + 
  geom_boxplot(aes(fill = Species)) +
  theme_minimal() +
  theme(legend.position = "top")
bp

# Scatter plot
sp <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + 
  geom_point(aes(color = Species)) +
  theme_minimal()+
  theme(legend.position = "top")

 

library(wesanderson)
# Discrete color
bp + scale_fill_manual(values = wes_palette("GrandBudapest1", n = 3))

# Gradient color
pal <- wes_palette("Zissou1", 100, type = "continuous")
ggplot(heatmap, aes(x = X2, y = X1, fill = value)) +
  geom_tile() + 
  scale_fill_gradientn(colours = pal) + 
  scale_x_discrete(expand = c(0, 0)) +
  scale_y_discrete(expand = c(0, 0)) + 
  coord_equal() 

 

单独绘制colorbar图,以我自己的数据为例


library(wesanderson)
pal <- wes_palette("Zissou1", 100, type = "continuous")


ggplot(new_id,aes(x=Group,y=1,fill=HR))+
  geom_bar(position="stack", stat="identity")+
  #scale_fill_grey(start = 0.8, end = 0.2)
  scale_fill_gradientn(colours = pal) +
  theme_classic()+coord_flip()

 

可单独进行编辑使用

更多资料详见: 

https://www.datanovia.com/en/blog/top-r-color-palettes-to-know-for-great-data-visualization/

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值