Mind the aspect ratio (original) (raw)

Aspect ratio is defined as the ratio of the width to the height of a graphic. It can have a strong impact on the insights gained from your graphic.

Here is an example with a line plot showing yearly sunspot numbers from 1749 to 1983. (Sunspots are temporary phenomena on the Sun’s photosphere that appear as spots darker than the surrounding areas.). The dataset comes from this scientific publication originally, related by Andrews et al..

# Libraries
library(tidyverse)
library(hrbrthemes)

# Load dataset: comes with R
data <- data.frame(
  Year = as.numeric(time(sunspot.year)),
  Sunspots = as.numeric(sunspot.year)
)

# Plot
data %>%
  ggplot( aes(x=Year, y=Sunspots)) +
    geom_line() +
    ggtitle("Number of sunspots per year") +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=12)
    )

The solar cycle is quite obvious on this figure. The sunspot numbers follow this periodic 11-year change in the sun’s activity, making the line go up and down quite regularly. It is also clear that some spikes are higher than others, with maximum smoothed sunspot numbers ranging from 50 to 180.

Playing with the aspect ratio


Now let’s change the aspect ratio of this figure, making it wider and less high. To exaggerate the effect, the graphic is zoomed to the 1800 to 1900 period:

# Plot
data %>%
  filter(Year>1800 & Year<1900) %>%
  ggplot( aes(x=Year, y=Sunspots)) +
    geom_line() +
    ggtitle("Number of sunspots per year") +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=12)
    )

The conclusions found using the first graphic are still true, but here a new pattern is visible. The sunspot number increases quicker than it decreases (ref). This is due to the fact that the sunspot decay rate is lower than the formation rate (ref).

On the first chart this pattern was not visible since the lines were almost vertical from the bottom to the top of the axis. Here, with the slope being less steep, this pattern becomes visible.

Interactivity


In this type of situation, producing an interactive graphic allows the user to zoom to a specific part and thus to try several different aspect ratio. Allowing this kind of exploration greatly improves the value of your graphic:

library(plotly)

# Plot
p <- data %>%
  ggplot( aes(x=Year, y=Sunspots)) +
    geom_line() +
    ggtitle("# of sunspots (select a zone to zoom in)") +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=12)
    )

ggplotly(p)

#Going further ***