Dataviz caveat
Consistency between charts

Let’s consider a small report where you present several graphics to your audience. The report is composed of:
- a barplot showing the total amount of money spent on the five products of the company
- a line plot showing the evolution of the money generated by these five products in the last ten years:
Show codeHide code
# 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
Here, it is very hard to make the link between the two charts, since the color palette used for each chart is different. Product A is in dark purple on the left graphic, and in red on the right one. It takes time to make the link.
Be consistent.
When you have several graphic, use the same color for the same item throughout the report:
Show codeHide code
# 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_viridis(discrete=TRUE) +
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
That’s better, isn’t it?
