Don’t use color if they communicate nothing

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




Colors are one of the main mediums used to convey information in dataviz. They allow to highlight groups or variation when used appropriately, but are confusing or misleading otherwise.

Here is an example showing the quantity of weapons exported by the top 20 largest exporters in 2017 (more info here):

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

# Load dataset from github
data <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum.csv", header=TRUE, sep=",")

# create random color palette
mycolors <- colors()[sample(1:400, nrow(data))]
  
# Barplot
data %>%
  filter(!is.na(Value)) %>%
  arrange(Value) %>%
  tail(20) %>%
  mutate(Country=factor(Country, Country)) %>%
  ggplot( aes(x=Country, y=Value, fill=Country) ) +
    geom_bar(stat="identity") +
    scale_fill_manual( values = mycolors ) +
    coord_flip() +
    theme_ipsum() +
    theme(
      panel.grid.minor.y = element_blank(),
      panel.grid.major.y = element_blank(),
      legend.position="none"
    ) +
    xlab("") +
    ylab("Weapon quantity (SIPRI trend-indicator value)")