Add color to your ggplot2 text in R

The ggplot2 deal is highly effective and nearly endlessly customizable, but sometimes smaller tweaks can be a problem. The ggtext deal aims to simplify styling textual content on your visualizations. In this tutorial, I’ll walk through 1 textual content-styling endeavor I saw demo’d at RStudio Meeting past thirty day period: including color.

If you’d like to observe alongside, I suggest putting in the progress version of ggplot2 from GitHub. In general, some things proven at the meeting weren’t on CRAN nevertheless. And ggtext certainly does not perform with some older variations of ggplot.

You have to put in ggtext from GitHub, due to the fact at the time I wrote this, the deal wasn’t nevertheless on CRAN. I use controllers::put in_github() to put in R offers from GitHub, though many other possibilities, such as devtools::put in_github(), perform as perfectly. Note that in the code under I include the argument build_vignettes = Legitimate so I have neighborhood variations of deal vignettes. Soon after that, I load ggplot2, ggtext, and dplyr.

controllers::put in_github("tidyverse/ggplot2", build_vignettes = Legitimate)
controllers::put in_github("wilkelab/ggtext", build_vignettes = Legitimate)

For demo data, I’ll use data evaluating tweets about R (with the #rstats hashtag) with tweets about Python (#python). Soon after downloading new tweets, I did some filtering, took a random sample of 1,000 of each, and then calculated how many in each team experienced at minimum five likes, experienced at minimum five retweets, included a URL, and included media like a photo or video clip.

You can re-produce the data established with the code block under. Or you could use any data established that makes feeling as a grouped bar chart and modify my subsequent graph code appropriately.

Leave a Reply

Your email address will not be published. Required fields are marked *