• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    R
  • License
    Other
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multivariate scales for ggplot2

multiscales

Multivariate scales for ggplot2, written by Claus O. Wilke

Installation

This package can be installed from github. It requires the development version of the colorspace package. It also requires ggplot2 3.0.0, which was released on July 3, 2018.

install.packages("colorspace", repos = "http://R-Forge.R-project.org")
devtools::install_github("clauswilke/multiscales")

This is an experimental package. Use at your own risk. API is not stable. No user support provided.

Examples

Visualizing the lead/lag of Clinton vs. Trump in the 2016 presidential election jointly with the uncertainty of the lead/lag estimates. This visualization shows that for many states the outcome was difficult to predict. (Example taken from Correll et al., Value-Suppressing Uncertainty Palettes, CHI 2018.)

library(ggplot2)
library(multiscales)

colors <- scales::colour_ramp(
  colors = c(red = "#AC202F", purple = "#740280", blue = "#2265A3")
)((0:7)/7)

ggplot(US_polling) + 
  geom_sf(aes(fill = zip(Clinton_lead, moe_normalized)), color = "gray30", size = 0.2) + 
  coord_sf(datum = NA) +
  bivariate_scale("fill",
    pal_vsup(values = colors, max_desat = 0.8, pow_desat = 0.2, max_light = 0.7, pow_light = 1),
    name = c("Clinton lead", "uncertainty"),
    limits = list(c(-40, 40), c(0, 1)),
    breaks = list(c(-40, -20, 0, 20, 40), c(0, 0.25, 0.50, 0.75, 1.)),
    labels = list(waiver(), scales::percent),
    guide = "colourfan"
  ) +
  theme_void() +
  theme(
    legend.key.size = grid::unit(0.8, "cm"),
    legend.title.align = 0.5,
    plot.margin = margin(5.5, 20, 5.5, 5.5)
  )

For comparison, the same plot with a univariate color scale. Not it appears that in every state we know who is in the lead.

ggplot(US_polling) + 
  geom_sf(aes(fill = Clinton_lead), color = "gray30", size = 0.2) + 
  coord_sf(datum = NA) +
  scale_fill_gradient2(
    low = "#AC202F", mid = "#740280", high = "#2265A3",
    name = c("Clinton lead", "uncertainty"),
    limits = c(-40, 40),
    breaks = c(-40, -20, 0, 20, 40),
    guide = guide_colorbar(
      direction = "horizontal",
      label.position = "bottom",
      title.position = "top",
      barwidth = grid::unit(4.0, "cm")
    )
  ) +
  theme_void() +
  theme(
    legend.title.align = 0.5,
    legend.key.size = grid::unit(0.8, "cm"),
    plot.margin = margin(5.5, 20, 5.5, 5.5)
  )

More Repositories

1

dataviz

A book covering the fundamentals of data visualization
HTML
3,179
star
2

colorblindr

An R package to simulate colorblindness on R figures.
R
306
star
3

ggjoy

Deprecated. Please use ggridges.
R
293
star
4

practical_ggplot2

Step-by-step examples of building publication-quality figures in ggplot2
HTML
167
star
5

ggtextures

Drawing textured rectangles and bars with ggplot
R
157
star
6

dviz.supp

Supporting materials for Claus Wilke's data visualization book
R
90
star
7

PeptideBuilder

A simple Python library to generate model peptides
Python
78
star
8

relayer

Rethinking layers in ggplot2
R
73
star
9

ggisoband

Drawing isolines and isobands with 'ggplot2'
R
49
star
10

sinab

Sinab is not a browser.
Rust
27
star
11

COVID19-IFR

COVID-19 Infection Fatality Rates
25
star
12

proteinER

Supporting code for the paper "Measuring evolutionary rates of proteins in a structural context"
Python
12
star
13

pinetree

🌲 a flexible gene expression simulator with codon-specific translation rates
C++
11
star
14

artifact

Complete code for generative art project The Artifact.
JavaScript
5
star
15

sneronoi

Stochastic neighbor embedding meets Voronoi tessellation.
JavaScript
5
star
16

structural_prediction_of_ER

Code and data for Shahmoradi et al., Predicting evolutionary site variability from structure in viral proteins: buriedness, packing, flexibility, and design, J. Mol. Evol. 79:130–142 (2014).
R
5
star
17

codon_tools

A python package containing various tools for codon optimization and de-optimization.
Python
4
star
18

Ecoli_FBA_input_prediction

Code and data for Sridhara et al., Predicting growth conditions from internal metabolic fluxes in an in-silico model of E. coli, PLOS ONE 9:e114608 (2014).
TeX
3
star
19

protein_design_and_site_variability

Code and data for Jackson et al, Amino-acid site variability among natural and designed proteins, PeerJ 1:e211 (2013).
Python
3
star
20

fxrandomjs

Deterministic pseudorandom number generator
JavaScript
3
star
21

GBM_genomics

TeX
3
star
22

clauswilke.github.io.old

HTML
3
star
23

zipcodes

Translate zip codes into fips codes
HTML
3
star
24

clauswilke.github.io

HTML
2
star
25

MACV_SMD

Code and data for Meyer et al, Analyzing Machupo virus-receptor binding by molecular dynamics simulations, PeerJ 2:e266 (2014).
Tcl
2
star
26

alien_clock

HTML
1
star
27

Omega_MutSel

Code and data for Spielman and Wilke, The relationship between dN/dS and scaled selection coefficients, Mol. Biol. Evol. 2015.
TeX
1
star
28

Guo_etal_SCV

Data and code for Guo et al., Single-cell virology
HTML
1
star