Consistency between charts

A collection of common dataviz caveats by Data-to-Viz.com




Let’s consider a report where you present several graphics to your audience. The little report is composed by:


# Libraries
library(tidyverse)
library(hrbrthemes)
library(patchwork)
library(viridis)

# create dummy data
data <- data.frame(
  product = LETTERS[1:5],
  value = c(10, 14, 18, 6, 15)
)

# Plot
a <- data %>%
  ggplot( aes(x=product, y=value, fill=product)) +
    geom_bar(stat="identity", width=0.5) +
    scale_fill_viridis(discrete=TRUE) +
    ggtitle("How much the products cost") +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=12),
      legend.position = "none"
    ) +
    xlab("") +
    ylab("Cost in M$")

# create dummy data
data <- data.frame(
  year = rep( seq(1,10), 5 ),
  product = rep(LETTERS[1:5], each=10 ),
  value = c( 
    seq(1,10) + sample( 1:3, 10, replace = TRUE), 
    seq(5,14) + sample( 4:10, 10, replace=TRUE), 
    seq(10,1)*2 + sample( 3:5, 10, replace=TRUE), 
    seq(20,11) + sample( 12:17, 10, replace=TRUE), 
    seq(1,10) + sample( 40:10, 10))
)

# Plot
b <- data %>%
  ggplot( aes(x=year, y=value, color=product)) +
    geom_line() +
    scale_color_discrete() +
    scale_x_continuous(breaks=c(1:10)) +
    ggtitle("How much the products make") +
    theme_ipsum() +
    theme(
      plot.title = element_text(size=12)
    ) +
    xlab("Year") +
    ylab("Benefit in M$")

# Show
a + b