Create "The Economist" Style Plots in R?
Asked Answered
G

1

6

This question has two parts, one more general and the other a specific case:

  1. Is there a theme or template in R for producing plots that have similar appearance to the charts published in "The Economist" magazine? Examples in other contexts include: Create "The Economist" style graphs from python for python and set scheme economist for Stata.

  2. Specifically, what would be the syntax (e.g., in ggplot2) to produce a groups bar plot that would look like the example below, colored shaped markers with bold lines spanning the range between them (left panel), or rectangular confidence intervals (right panel)?

enter image description here

Source: https://www.economist.com/graphic-detail/2020/04/01/covid-19-may-be-far-more-prevalent-than-previously-thought

Golightly answered 12/4, 2020 at 9:55 Comment(0)
G
6

Yes you have it in ggthemes (extension of ggplot2) with theme_economist and theme_economist_white.

For the bar plot, you will need to play with geom_bar and coord_flip (here)

Examples from ggthemes doc (here)

library("ggplot2")
library("ggthemes")

p <- ggplot(mtcars) +
     geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
     facet_wrap(~am) +
     # Economist puts x-axis labels on the right-hand side
     scale_y_continuous(position = "right")

## Standard
p + theme_economist() +
  scale_colour_economist()

enter image description here

## White
p + theme_economist_white() +
  scale_colour_economist()

enter image description here

How to reproduce the plot given in example

Since I cannot install SciencesPo package in my computer, I propose you a ggplot + ggthemes approach.

A good starting point might be the following approach. I use as an example the diamond dataset.

library(dplyr)
library(ggplot2)
library(ggthemes)

df <- diamonds %>%
  group_by(cut) %>%
  summarise(mean = mean(price), sigma = sd(price),
            n = n())
df <- df %>%
  mutate(int_minus = mean - 1.96*sigma/sqrt(n),
         int_plus = mean + 1.96*sigma/sqrt(n))

And then the plot

ggplot(df) +
  geom_segment(aes(x = int_minus, xend = int_plus, y = factor(cut), yend = factor(cut)), size = 2L, alpha = 0.4) +
  geom_point(aes(x = mean, y = factor(cut)), shape = 15, color = "blue", size = 4L) +
  theme_economist_white()

enter image description here

Guzman answered 12/4, 2020 at 9:58 Comment(3)
that fully resolves 1. For 2., I think geom_segment is more appropriate than bar, just figuring it out.Golightly
even better: geom_dumbbell from the SciencesPo package, otherwise one needs to combine segments and points.Golightly
I made an edit to show something that can be used as a basis for the plot. The confidence intervals are manually computed in my case, don't know how the economist proceeds in the COVID caseGuzman

© 2022 - 2024 — McMap. All rights reserved.