Git Product home page Git Product logo

metbrewer's Introduction

MetBrewer

Palettes inspired by works at the Metropolitan Museum of Art in New York. Pieces selected come from various time periods, regions, and mediums.

CRAN Version CRAN Downloads

Structure of the package was based on coding from the PNWColors and wesanderson packages. Inspired by the package RColorBrewer from the work of Cynthia Brewer.

For requests, questions, comments, concerns, or any thing else, feel free to reach out to me:
My Website: here
Twitter: here
LinkedIn: here
Email: [email protected]

Content

Installation

Palettes

Functions

Colorblind Checking

Install Package

R

MetBrewer is now able to be downloaded directly through R. You can still download through GitHub as well.

install.packages("MetBrewer")

install.packages("devtools")
devtools::install_github("BlakeRMills/MetBrewer")

Python

Install the package under the Python/ directory directly:

python setup.py install

or via pip:

pip install .

or place the file into your source directory.

Use it in your code:

import met_brewer
colors = met_brew(name="VanGogh1", n=123, brew_type="continuous")

Palettes

All Palettes

AllPals

Archambault

Archambault

  • Woman’s Dress and Accessories, 2005, Jodi Archambault, Hunkpapa Lakota (Teton Sioux), Link
  • Colorblind-Friendly

Austria

Austria

  • Adoration of the Magi from Seven Scenes from the Life of Christ, 1390, Artists Unknown, Austrian, Link

Benedictus

Benedictus

  • Relais, 1930 : quinze planches donnant quarante-deux motifs décoratifs : enluminure d'art de J. Saudé : préliminaires de Y. Rambosson, 1930, Edouard Bénedictus, French, Link

Cassatt1

Cassatt

  • The Cup of Tea, 1880-1881, Mary Cassatt, American, Link
  • Colorblind-Friendly

Cassatt2

Cassatt2

  • Lilacs in a Window (Vase de Lilas a la Fenetre), 1880–83, Mary Cassatt, American, Link
  • Colorblind-Friendly

Cross

Cross

  • Cap Nègre, 1909, Henri-Edmond Cross, French, Link

Degas

Degas

  • The Rehearsal of the Ballet Onstage, 1874, Edgar Degas, French, Link

Demuth

Demuth

  • I Saw the Figure 5 in Gold, 1928, Charles Demuth, American, Link
  • Colorblind-Friendly

Derain

Derain

  • The Palace of Westminster, 1906–1907, André Derain, French, Link
  • Colorblind-Friendly

Egypt

Egypt

  • The King with Isis, Tomb of Haremhab, A.D. 1910–1911; original ca. 1323–1295 B.C., Twentieth Century; original New Kingdom, Link
  • Colorblind-Friendly

Gauguin

Gauguin

  • A Farm in Brittany, 1874, Paul Gauguin, French, Link

Greek

Greek

  • Terracotta neck-amphora (jar), ca. 550–540 B.C., Greek, Link
  • Colorblind-Friendly

Hiroshige

Hiroshige

  • Sailing Boats Returning to Yabase, Lake Biwa, 1835, Utagawa Hiroshige, Japanese, Link
  • Colorblind-Friendly

Hokusai1

Hokusai

  • Poem by Gon-Chūnagon Sadaie, from the series One Hundred Poems Explained by the Nurse (Hyakunin isshu uba ga etoki), 1760–1849, Katsushika Hokusai, Japanese, Link

Hokusai2

Hokusai2

  • Lake Suwa in Shinano Province (Shinshū Suwako), from the series Thirty-six Views of Mount Fuji (Fugaku sanjūrokkei), 1830-32, Katsushika Hokusai, Japanese, Link
  • Colorblind-Friendly

Hokusai3

Hokusai3

  • Yōrō Waterfall in Mino Province (Mino no Yōrō no taki), from the series A Tour of Waterfalls in Various Provinces (Shokoku taki meguri), 1832, Katsushika Hokusai, Japanese, Link
  • Colorblind-Friendly

Homer1

Homer1

  • The Veteran in a New Field, 1865, Winslow Homer, American, Link

Homer2

Homer2

  • Flower Garden and Bungalow, Bermuda, 1899, Winslow Homer, American, Link

Ingres

Ingres

  • Joséphine-Éléonore-Marie-Pauline de Galard de Brassac de Béarn (1825–1860), Princesse de Broglie, 1851–53, Jean Auguste Dominique Ingres, French, Link
  • Colorblind-Friendly

Isfahan1

Isfahan1

  • Mihrab (Prayer Niche), dated A.H. 755/ A.D. 1354–55, From Iran, Isfahan, Link
  • Colorblind-Friendly

Isfahan2

Isfahan2

  • Garden Gathering, 1640–50, From Iran, Isfahan, Link
  • Colorblind-Friendly

Java

Java

  • Skirt, 20th Century, Javanese People, Javanese, Link
  • Colorblind-Friendly

Johnson

Johnson Jitterbugs V, 1941–42, William Henry Johnson, American, Link

  • Colorblind-Friendly

Juarez

Juarez

  • The Entombment of Christ, 1702, Juan Rodríguez Juárez, Mexican, Link

Kandinsky

Kandinsky Kleine Welten IV (Small Worlds IV), 1922, Vasily Kandinsky, French, born Russia, Link

  • Colorblind-Friendly

Klimt

Klimt

  • Mäda Primavesi (1903–2000), 1912-13, Gustav Klimt, Austrian, Link

Lakota

Lakota

  • Dress, 1870, Lakota/Teton Sioux, Native American, Link

Manet

Manet

  • Boating, 1874, Edouard Manet, French, Link

Monet

Monet

  • Bridge over a Pond of Water Lilies, 1899, Claude Monet, French, Link

Moreau

Moreau

  • Oedipus and the Sphinx, 1864, Gustave Moreau, French, Link

Morgenstern

Morgenstern

  • Jungfrau, Mönch, and Eiger, 1851, Carl Morgenstern, German, Link
  • Colorblind-Friendly

Nattier

Nattier

  • Madame Bergeret de Frouville as Diana, 1756, Jean Marc Nattier, French, Link

Navajo

Navajo

  • Serape, 1865–70, Navajo, Link

NewKingdom

NewKingdom

  • Blue-Painted Ibex Amphora from Malqata, ca. 1390–1353 B.C., New Kingdom, Link

Nizami

Nizami

  • "Laila and Majnun in School", Folio 129 from a Khamsa (Quintet) of Nizami of Ganja, A.H. 931/A.D. 1524–25, Nizami, Made in present-day Afghanistan, Herat, Link

OKeeffe1

OKeeffe1

  • From the Faraway, Nearby, 1937, Georgia O'Keeffe, American, Link
  • Colorblind-Friendly

OKeeffe2

OKeeffe2

  • Red and Yellow Cliffs, 1940, Georgia O'Keeffe, American, Link
  • Colorblind-Friendly

Paquin

Paquin

  • Evening Dress, 1937, House of Paquin by Ana de Pombo, French House, Spanish Designer, Link

Peru1

Peru1

  • Ear Ornament, Winged Runner, A.D. 400–700, Moche, Peruvian, Link

Peru2

Peru2

  • Tunic with Confronting Catfish, A.D. 800–850, Nasca-Wari, Peruvian, Link

Pillement

Pillement

  • A Shipwreck in a Storm, 1782, Jean Pillement, French, Link
  • Colorblind-Friendly

Pissaro

Pissaro

  • Washerwoman, Study, 1880, Camille Pissarro, French, Link

Redon

Redon

  • Pandora, 1914, Odilon Redon, French, Link

Renoir

Renoir

  • Nini in the Garden (Nini Lopez), 1876, Auguste Renoir, French, Link

Signac

Signac

  • Notre-Dame-de-la-Garde (La Bonne-Mère), Marseilles, 1905-06, Paul Signac, French, Link

Tam

Tam

  • Dragon Robe, 1998, Vivienne Tam, American, born China, Link
  • Colorblind-Friendly

Tara

Tara

  • Maharana Sarup Singh Inspects a Prize Stallion, 1845–46, Tara, Western India, Rajasthan, Mewar, Link

Thomas

Thomas

  • Formes et couleurs: vingt planches en couleurs contenant soixante-sept motifs decoratifs, 1921, Auguste H. Thomas, French, Link

Tiepolo

Tiepolo

  • The Glorification of the Barbaro Family, 1750, Giovanni Battista Tiepolo, Italian, Link

Troy

Troy

  • The Declaration of Love, 1724, Jean François de Troy, French, Link
  • Colorblind-Friendly

Tsimshian

Tsimshian

  • Headdress frontlet, 1820–40, Tsimshian, Native American (Canadian), Link

VanGogh1

VanGogh1

  • Cypresses, 1889, Vincent van Gogh, Dutch, Link

VanGogh2

VanGogh2

  • Self-Portrait with a Straw Hat (obverse: The Potato Peeler), 1887, Vincent van Gogh, Dutch, Link

VanGogh3

VanGogh3

  • First Steps, after Millet, 1890, Vincent van Gogh, Dutch, Link
  • Colorblind-Friendly

Veronese

Veronese

  • Mars and Venus United by Love, 1570s, Paolo Veronese, Italian, Link
  • Colorblind-Friendly

Wissing

Wissing

  • Portrait of a Woman, 1687, Willem Wissing, Dutch, Link

Functions

You can retrieve palettes using various methods listed below.

Python
met_brew(name="VanGogh1", n=7, brew_type="discrete")

R
met.brewer(name="VanGogh1", n=7, type="discrete")

Ex1

Python
met_brew(name="Manet", n=5)

R
met.brewer("Manet", 5)

Ex2

Python
met_brew("Morgenstern")

R
met.brewer("Morgenstern")

Ex3

Python
met_brew("Troy", n=15, brew_type="continuous")

R
met.brewer("Troy", n=15, type="continuous")

Ex4

Python
met_brew("Hokusai1", n=100, brew_type="continuous")

R
met.brewer("Hokusai1", n=100)

Ex5

ggplot2 Examples

Here are also some ways you can incorporate this package into {ggplot2}

ggplot(data=iris, aes(x=Species, y=Petal.Length, fill=Species)) +
  geom_violin() +
  scale_fill_manual(values=met.brewer("Greek", 3))

Ex6

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
  geom_point(size=2) +
  scale_color_manual(values=met.brewer("Renoir", 3))

Ex7

ggplot(data=iris, aes(x=Species, y=Sepal.Width, color=Sepal.Width)) +
  geom_point(size=3) +
  scale_color_gradientn(colors=met.brewer("Isfahan1"))

Ex8

library(urbnmapr)
countydata %>%
  left_join(counties, by = "county_fips") %>%
  filter(state_name =="Nebraska") %>%
  ggplot(mapping=aes(long,lat,group = group, fill = horate)) +
  geom_polygon(color="black",size=.25) +
  scale_fill_gradientn(colors = met.brewer("Morgenstern")) +
  coord_fixed() +
  labs(fill="Homeownership rate") +
  theme_void()

Ex9

Colorblind Friendly Checking

The package has been updated to check for colorblind-friendlyness You can list out the colorblind-friendly palettes with the following code

Python
for palette_name, palette_dict in COLORBLIND_PALETTES.items():
    print(palette_name)
    
[1] Cassatt1, Cassatt2, Derain, Egypt, Greek, Hiroshige, Hokusai2, Hokusai3, Ingres
[2] Isfahan1, Isfahan2, Morgenstern, OKeeffe1, OKeeffe2, Pillement, Troy, VanGogh3, Veronese

R
MetBrewer::colorblind_palettes

 [1] "Archambault" "Cassatt1"    "Cassatt2"    "Demuth"      "Derain"      "Egypt"       "Greek"       "Hiroshige"  
 [9] "Hokusai2"    "Hokusai3"    "Ingres"      "Isfahan1"    "Isfahan2"    "Java"        "Johnson"     "Kandinsky"  
[17] "Morgenstern" "OKeeffe1"    "OKeeffe2"    "Pillement"   "Tam"         "Troy"        "VanGogh3"    "Veronese"   

You can also test is a palettes is colorblind friendly using the function provided

Python
is_colorblind_friendly("Ingres")
[1] True

R
MetBrewer::colorblind.friendly("Ingres")
[1] TRUE

metbrewer's People

Contributors

blakermills avatar git-thor avatar louisfaure avatar ojwatson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

metbrewer's Issues

Feature Request: Export formats of color codes

Provide a helper function for exporting the colors to different formats, e.g. decimal, relative 0 to 1, xml strings etc.

Currently, the color codes are native to hexadecimal strings.

The API could support a dictionary as data type which can be directly converted to a JSON file for instance for later use.

Decimal DEC

{'colors': [(221, 81, 41), (15, 122, 162), (66, 178, 131), (250, 178, 85)],
 'name': 'Egypt'}

Relative [0, 1] REL

{'colors': [(0.8666666666666667, 0.3176470588235297, 0.1607843137254903),
            (0.05882352941176472, 0.48235294117647026, 0.6352941176470588),
            (0.26274509803921564, 0.6980392156862745, 0.5176470588235293),
            (0.9803921568627451, 0.6980392156862747, 0.33333333333333337)],
 'name': 'Egypt'}

XML

{'colors': [(0.8666666666666667, 0.3176470588235297, 0.1607843137254903),
            (0.05882352941176472, 0.48235294117647026, 0.6352941176470588),
            (0.26274509803921564, 0.6980392156862745, 0.5176470588235293),
            (0.9803921568627451, 0.6980392156862747, 0.33333333333333337)],
 'name': 'Egypt',
 'tags': ['<color name="Egypt-1" value="0.8666666666666667 0.3176470588235297 '
          '0.1607843137254903" />',
          '<color name="Egypt-2" value="0.05882352941176472 '
          '0.48235294117647026 0.6352941176470588" />',
          '<color name="Egypt-3" value="0.26274509803921564 0.6980392156862745 '
          '0.5176470588235293" />',
          '<color name="Egypt-4" value="0.9803921568627451 0.6980392156862747 '
          '0.33333333333333337" />']}
<color name="Egypt-1" value="0.8666666666666667 0.3176470588235297 0.1607843137254903" />
<color name="Egypt-2" value="0.05882352941176472 0.48235294117647026 0.6352941176470588" />
<color name="Egypt-3" value="0.26274509803921564 0.6980392156862745 0.5176470588235293" />
<color name="Egypt-4" value="0.9803921568627451 0.6980392156862747 0.33333333333333337" />

Labels not working for scale_*_met_d()

Hi Blake,

I love this newest version of MetBrewer so much! I've been introducing colleagues to it very enthusiastically. Unfortunately I just spotted that I can't set custom legend labels in scale_*_met_d() using labels in the usual way. Here's an example.

data(iris)

iris_labs <- paste("I.", levels(iris$Species))
names(iris_labs) <- levels(iris$Species)

# Species labels changed successfully
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) +
  geom_point() +
  scale_colour_discrete(labels = iris_labs)

# Species labels not changed
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) +
  geom_point() +
  scale_colour_met_d("Renoir", labels = iris_labs)

Not a huge issue, but worth keeping in mind for future versions!

Cheers,
Lyuba

Add a transparency argument for R

Hello, many thanks for MetBrewer! Would it be possible to add an argument for transparency? Ideally it would be a vector that control the transparency of each colour of the palette (with the possibility of recycling the vector on R).

I think you are using colorRampPalette in you generator. There is now an argument alpha for the transparency. See this answer on stackoverflow

Duplicated argument name "name"

Hi Blake, thanks for these great palettes and for including {ggplot2} scales! I just noticed that you are using name as the argument for the palette name. Unfortunately, this is overriding the usual name argument to control the title of the legend. May you consider changing it to something else, e.g. palette or option?

`...` arg missing from ggplot2 calls

Howdy! The package documentation notes that the arg ... can be used to pass arguments to underlying ggplot2 functions (scale_*_gradientn() and discrete_scale()), but looking at the function internals, this is actually missing (found this out when trying to get the limits arg for scale_color_gradientn() to work). It should be a pretty easy add --- let me know if you'd like me to open a PR

Istallation issue

Hello, when I run the installation code in RStudio:

devtools::install_github("BlakeRMills/MetBrewer")

I get the following error message:
Error: Failed to install 'unknown package' from GitHub:
HTTP error 404.
No commit found for the ref master

Did you spell the repo owner (BlakeRMills) and repo name (MetBrewer) correctly?

  • If spelling is correct, check that you have the required permissions to access the repo.

Seurat

Hi!
Love the color palettes!
a quick idea that I think those of us analyzing single cell sequencing data would get a kick out of-
The most popular package for these analyses is called Seurat since we make a lot of UMAP plots, and it looks like Study for "A Sunday on La Grande Jatte" has been in and out of the Met's collection a few times 👀

How to set pallet in ggplot2

Hello, thanks for MetBrewer!

Could you show how i can apply palettes from it to ggplot2 plots?

For example, next code it works,

library(ggplot2)
library(MetBrewer)

ggplot(data=iris, 
       aes(x=Sepal.Length, 
           y=Petal.Length, 
           color=Species))+
  ggtitle("Iris")+
  geom_point()+
  scale_color_manual(values = MetBrewer::MetPalettes$Cross[[1]][1:3])

but i think there should be a more graceful way to apply the palette.

Conda package

Thanks for the neat package!

I just wanted to let you know the package has been added to Conda Forge (r-metbrewer-feedstock), so those who manage R environments with Conda can install it with:

conda install -c conda-forge r-metbrewer

The Conda Forge repository automatically tracks CRAN, so there isn't anything here that needs to change. There are some Conda Forge badges available (see README), in case you want to add them to the README here. E.g.,

Conda Version Conda Downloads

Feel free to close this Issue after reading - just want to share the info.

... not being passed to scale_fill_met_c

scale_fill_met_c does not currently pass the ... argument which means none of the additional options (e.g. limits, oob) get passed to scale_fill_gradientn

# no limits
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, fill = Petal.Length)) + 
  geom_tile() +
  scale_fill_met_c(name = "Homer1", limits = c(0,4), oob = scales::squish)
# correct passing of ...
scale_fill_met_c <- function(name, direction=1, ...){
  `%notin%` <- Negate(`%in%`)
  if (direction %notin% c(1, -1)){
    stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.")
  }
  scale_fill_gradientn(colors=met.brewer(name=name, direction=direction, override.order = F), ...) # passed
}

# fixed
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, fill = Petal.Length)) + 
  geom_tile() +
  scale_fill_met_c(name = "Homer1", limits = c(0,4), oob = scales::squish)
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.3.6   MetBrewer_0.2.0

loaded via a namespace (and not attached):
 [1] magrittr_2.0.3   tidyselect_1.1.2 munsell_0.5.0    colorspace_2.0-3 R6_2.5.1         rlang_1.0.2      fansi_1.0.3      dplyr_1.0.9     
 [9] tools_4.2.0      grid_4.2.0       gtable_0.3.0     utf8_1.2.2       cli_3.3.0        DBI_1.1.2        withr_2.5.0      ellipsis_0.3.2  
[17] assertthat_0.2.1 tibble_3.1.7     lifecycle_1.0.1  crayon_1.5.1     purrr_0.3.4      vctrs_0.4.1      glue_1.6.2       compiler_4.2.0  
[25] pillar_1.7.0     generics_0.1.2   scales_1.2.0     pkgconfig_2.0.3

Python example not working

The Python example in the README.md does not work when importing as import met_brewer. It returns: NameError: name 'met_brew' is not defined.
The easiest way to temporarily solve it is by directly calling the function, from met_bewer import met_brew. This behavior occurs on various laptops and OS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.