A ggplot2 version of this article. Data setup:
# set up the data
df <- data.frame(Circulatory=c(32,26,19,16,14,13,11,11),
Mental=c(11,11,18,24,23,24,26,23),
Musculoskeletal=c(17,18,13,16,12,18,20,26),
Cancer=c(10,15,15,14,16,16,14,14))
df$year <- seq(1975,2010,by=5)
Now the plot, using tidyr and ggplot2:
library(tidyr)
library(ggplot2)
gathered <- gather(df, cause, percentage, -year)
crossed <- crossing(gathered, highlight = unique(gathered$cause))
ggplot(crossed, aes(year, percentage, group = cause,
color = highlight == cause)) +
geom_line(show.legend = FALSE) +
facet_wrap(~ highlight) +
scale_color_manual(values = c("gray", "darkblue")) +
theme_minimal()
For the curious: this works by quadrupling the dataset, once for each highlight:
head(crossed)
## year cause percentage highlight
## 1 1975 Circulatory 32 Cancer
## 2 1975 Circulatory 32 Circulatory
## 3 1975 Circulatory 32 Mental
## 4 1975 Circulatory 32 Musculoskeletal
## 5 1980 Circulatory 26 Cancer
## 6 1980 Circulatory 26 Circulatory