How to do it...

Keep in mind that visualizing fewer lines is much easier than visualizing a bunch of them:

  1. Load ggplot2 and use geom_line() to get it done:
> library(ggplot2)> ggplot(data = macro,          aes(x = year, y = trade, colour = country)) +          geom_line()

Outputted graph might be similar to the following figure:

Figure 5.8: Line plot draw by ggplot2
  1. To make it interactive, one can load ggvis and trust layer_lines() to the quest:
> library(ggvis)> ggvis(data = macro %>% droplevels(),         x = ~year, y = ~trade, stroke = ~country) %>%    layer_lines()
  1. Loading plotly, filter the data set and use add_traces() to draw lines for each country:

Get R Data Visualization Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.