"

Five quick #rstats tips I’ve picked up in the plots I made for my second #30DayChartChallenge

The one I don’t mention here is that you definitely get faster as you go. These challenges are a great way of building up a library of code and skills you can draw on for future projects!
Author
Affiliation

Building Stories with Data

Published

April 6, 2022

1. Need to plot a million points and ggplot() is taking too long but you want to stay within the tidyverse?

👉 Use 📦 {scattermore} with geom_scattermore() 🥳


 2. Using several subplots together to tell a story and they each have their own colour scheme?

👉 Create a function to blend in a bit of the same colour into all the others to create a more unified look

Code snippet in an R environment defining a function 'blend' that uses the monochromeR package to generate a colour palette. It outputs a hex code by blending 'green' with the colour '#2C3D4F', yielding '#03ED07'. Dark theme enhances visibility.

blend <- function(colour) {
  monochromeR::generate_palette(
    colour,
    blend_colour = "#2C3D4F",
    n_colours = 10
  )[2]
}

blend("green")
# "#03ED07"

3. Struggling with squished images when using {ggimage}?

👉 Plot the data with a ratio of 1:1 and use coord_equal() 👉 If that’s not an option (e.g. x is categorical), adjust the ratio of the x to y increments within coord_fixed(), e.g.:

A dark code snippet on a grey background displays the function `coord_fixed(ratio = 10)` in cyan text, indicating a fixed-coordinate setting with a ratio of 10. The design is framed like a terminal window with red, yellow, and green buttons, enhancing visual clarity.

4. Picked a nice font and then realised it doesn’t do numbers?

👉If there’s a similar one that will do for numbers, change font on the fly with 📦{ggtext} and element_markdown(), e.g.:

Code snippet for a plot title and subtitle. Title: 'Two in a Million'. Subtitle: 'What about the other 6.033 billion?', styled in 'Alternative Font'. Subtitle theme: 'Preferred Font That Doesn't Do Numbers'. Simple design with a dark background.

5. And finally, the one I really wish I’d known earlier. Want to change the background colour of your plot?

👉 No need to change everything within +theme()! Instead, pass the colour into ggsave! 🤯

Would have saved me a lot of time on so many #tidyTuesday plots!

Code snippet shows `ggsave` function for exporting a plot. Parameters: filename as '1.comparisons-part-2.png', height 10, width 9, background colour '#f5f5f5', and DPI 400. Presented on a dark, organised coding interface.

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2022. “Five Quick #Rstats Tips I’ve Picked up in the Plots I Made for My Second #30DayChartChallenge.” April 6, 2022. https://www.cararthompson.com/posts/2022-04-06-five-quick-rstats-tips-ive/.