The chaging US technology sector

How to make charts like this one with the streamgraph package.

Get the data & make a color map

library(dplyr)
library(streamgraph)
library(viridis)

stocks_url <- "http://infographics.economist.com/2015/tech_stocks/data/stocks.csv"
stocks <- read.csv(stocks_url, stringsAsFactors=FALSE)

stock_colors <- viridis_pal()(100)

Percent of total

stocks %>% 
  mutate(date=as.Date(quarter, format="%m/%d/%y")) %>% 
  streamgraph(key="ticker", value="nominal", offset="expand") %>% 
  sg_fill_manual(stock_colors) %>% 
  sg_axis_x(tick_interval=10, tick_units="year") %>% 
  sg_legend(TRUE, "Ticker: ")

Nominal

stocks %>% 
  mutate(date=as.Date(quarter, format="%m/%d/%y")) %>% 
  streamgraph(key="ticker", value="nominal", offset="zero") %>% 
  sg_fill_manual(stock_colors) %>% 
  sg_axis_x(tick_interval=10, tick_units="year") %>% 
  sg_legend(TRUE, "Ticker: ")

Real

stocks %>% 
  mutate(date=as.Date(quarter, format="%m/%d/%y")) %>% 
  streamgraph(key="ticker", value="real", offset="zero") %>% 
  sg_fill_manual(stock_colors) %>% 
  sg_axis_x(tick_interval=10, tick_units="year") %>% 
  sg_legend(TRUE, "Ticker: ")