dataviz

R Rainbows: Making a Pride Flag in R

🌈HAPPY PRIDE MONTH!! Fun fact: my rainbow Twitter banner (which I keep up year-round) was actually made using R! Given that pride season is officially upon us, I thought it’d be fun to share the code I wrote to generate a quick, fun ggplot rainbow flag. To make the flag, I wrote a function, rainbow_flag(), which depends on one parameter, n. This will control how many colors of the rainbow I want to use (see examples below).

Formatting Math Symbols and Expressions in ggplot Labels

Yesterday, I was trying to put some finishing touches on a figure I made in ggplot2 that visualizes some simulation results. The plot features several panels using facet_grid(), and uses colors to distinguish between different regression models that were fit to the simulated data. I wanted to label certain axes and panel names using the Greek letters I had used as parameter notation, and I also wanted the labels in the color legend to correspond to the different regression models I had fit.