It really is an amazing pigeon. Apologies that I haven’t a photo credit for it; I found it one day on twitter as it went viral. It is a New York City pigeon.
I want to color something with colors from that pigeon. First, I have to get the color palette.
imgpalr
has a package called imgpalr that will extract colors from an image. If I need to, it is install.packages("imgpalr").
In the following code chunk, I will load the package and then I want to point it to the pigeon image that I downloaded. In my case, it is in the same directory as the R Markdown file and is called Pigeon.png.
Inside the command image_pal(), I point it to an image, I specify how many colors [5], what type of color scheme, I want qualitative, and then some characteristics of the colors. The plot will show me the image alongside the palette though it is upside down.
library(imgpalr)Pigeon.colors <-image_pal("img/Pigeon.png", # This will need to be adjusted to the actual file location on your computer. Mine is in my downloads.n =5, # How many colors?type ="qual", # Type of palette?saturation =c(0.75, 1), brightness =c(0.75, 1), plot =TRUE, # Show the image and the palette?bw =c(0.7, 0.95) )
I want to graph it using a barplot equivalent because I have the height of the bars in vals. Let me use the fill aesthetic to fill the bars in by the five discrete things stored as Stuff. The trick to using it is to manually specify the colors and point it to the Pigeon.colors above.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2022. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.