ITADN
jakelawlor/PNWColors
jakelawlor/PNWColors · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

PNWColors

四年时光,定格于世界上最美丽的地方,并以此打造了一个 R 色彩调色板包。愿华盛顿州和太平洋西北地区的色彩,永远留存于我们的演示图表之中。

这些调色板取自我在一些我所知的最梦幻、色彩最丰富、最具 PNW 风情的地方拍摄的照片。Pantone Studio iPhone app 帮助我提取了颜色,而 Chroma.js Color Palette Helper 则帮助我调整数值,以确保所有调色板都是 color-blind safe,可用于制作美观且包容的数据可视化。

代码结构受到了 wesandersonLaCroixColoR 包的启发。See more examples on twitter.

Installation
Palettes
Functions
Examples
As Seen In
Contact

CRAN Downloads

安装包


# from CRAN
install.packages("PNWColors")

# or dev version:
install.packages("devtools") 
devtools::install_github("jakelawlor/PNWColors") 

用法

library(PNWColors)

names(pnw_palettes)
 [1] "Starfish" "Shuksan"  "Bay"      "Winter"   "Lake"     "Sunset"   "Shuksan2" 
 [8] "Cascades" "Sailboat" "Moth" "Spring"   "Mushroom" "Sunset2"  "Anemone"    

调色板

  • 低潮 -- 华盛顿州圣胡安群岛

  • 从贝克山滑雪场眺望舒克山 -- 华盛顿州北喀斯喀特

  • 夏末的日落划船之夜,别林汉姆湾,华盛顿

  • 西雅图雪灾 2019 -- 华盛顿州阿纳科特斯

  • 密西西比河以西最佳下班后晒太阳地点 -- 惠斯勒湖,华盛顿州阿纳科特斯

  • 华盛顿公园日落 -- 华盛顿州阿纳科特斯

  • 舒克山,黄金时刻 -- 华盛顿州北喀斯喀特山脉

  • 沃森湖步道尽头 -- 华盛顿州北喀斯喀特

  • 最美丽的蛾类 -- 华盛顿州 Vendovi 岛

  • S/V Funky Dory,首航 -- 华盛顿州阿纳科特斯

  • 牡蛎穹顶日落 -- 华盛顿州查库纳特

  • 樱花季 -- 华盛顿州阿纳科特斯

  • Fieldtrip -- 华盛顿州阿纳科特斯

  • 原木上的生活 -- 华盛顿州奥卡斯岛

构建调色板

使用 pnw_palette() 函数来构建和查看调色板。输入参数为 'name'、'n' 和 'type'(连续或离散)。'Name' 是必需的。如果 'n' 为空,函数将假设 n 等于调色板中的颜色数量(5-8),但如果 n > 调色板长度,它会自动在颜色之间进行插值。如果缺少 'type',当 n < palette length, and "continuous" if n > 调色板长度时,函数将假设为 "discrete"。

pnw_palette(name="Starfish",n=7,type="discrete")
pnw_palette("Winter",100)
pnw_palette("Bay",8,type="continuous")
pnw_palette("Moth",12)

示例图

调色板可以轻松集成到 Base R 成像或 ggplot2 中。

pal <- pnw_palette("Shuksan",100)
image(volcano, col = pal)
pal=pnw_palette("Lake",5, type = "discrete")
ggplot(diamonds, aes(carat, fill = cut)) +
  geom_density(position = "stack") +
  scale_fill_manual(values=pal)  +
  theme_classic()
pal=pnw_palette("Shuksan2",100)
ggplot(data.frame(x = rnorm(1e4), y = rnorm(1e4)), aes(x = x, y = y)) +
  geom_hex() +
  coord_fixed() +
  scale_fill_gradientn(colours = pal) +
  theme_classic()
  
  # Or, to switch the order, use rev(), see below
  scale_fill_gradientn(colours = rev(pal))
library(palmerpenguins)
ggplot(data = penguins, 
       aes(x = flipper_length_mm,
           y = body_mass_g)) +
  geom_point(aes(color = species, 
                 shape = species),
             size = 3) +
  scale_color_manual(values = pnw_palette("Bay",3)) +
  labs(title = "Penguin size, Palmer Station LTER",
       subtitle = "Flipper length and body mass for Adelie, Chinstrap and Gentoo Penguins",
       x = "Flipper length (mm)",
       y = "Body mass (g)",
       color = "Penguin species",
       shape = "Penguin species") +
  theme_classic()
pal <- pnw_palette("Anemone",3)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) + 
 geom_violin(trim=FALSE)+
 geom_boxplot(width=0.1, fill="white")+
 labs(title="Plot of length  by dose",x="Dose (mg)", y = "Length")+
 scale_fill_manual(values=pal)+
 theme_classic()
library(tidyverse)
library(urbnmapr)
pal <- pnw_palette("Winter",100)
countydata %>%
 left_join(counties, by = "county_fips") %>%
 filter(state_name =="Washington") %>%
 ggplot(mapping=aes(long,lat,group = group, fill = horate)) +
 geom_polygon(color="black",size=.25) +
 scale_fill_gradientn(colours = pal) +
 coord_map(projection="albers",lat0=39,lat1=45) +
 theme(legend.title = element_text(),
       legend.key.width = unit(.5,"in")) +
 labs(fill="Homeownership rate") +
 theme_void()
 

案例展示:

你是否在某个项目中使用了 PNWColors?请分享以扩充此列表!


Lawlor and Arellano 2020, Scientific Reports, Bay 调色板


Patel et al. 2020, Biogeochemistry, Sailboat 调色板


Nicholas et al. 2020, Journal of Physical Chemistry C, Sunset2 调色板


Sobocinski, K.L. (2021). Salish Sea Institute, Starfish 调色板


Linardich et al. (2021). Global Change Biology, Bay 调色板


Green et al. (2022). Proceedings B., Bay 调色板



联系方式

请通过 jake.lawlor@mail.mcgill.ca@Jake_Lawlor1

如需引用信息,请参见此处:DOI

Jake Lawlor (2020). PNWColors: Color Palettes Inspired by Nature in the US Pacific Northwest. R package version 0.1.0. https://CRAN.R-project.org/package=PNWColors

本工作由 NSF 资助项目 #1538626 支持