2016-02-24

Your turn

  • What is a (data) plot?
  • What are the three most important data plots?

Your turn

How would you describe this plot?

Using the package ggplot2

Elements of a plot

  • data
  • aesthetics: mapping of variables to graphical elements
  • geom: type of plot structure to use
  • transformations: log scale, …

Additional components

  • layers: multiple geoms, multiple data sets, annotation
  • facets: show subsets in different plots
  • themes: modifying style

Have you opened your project?

Data - Currency cross rates

Extracted from http://openexchangerates.org, extracted using the json api, with the R package, jsonlite.

library(readr)
rates <- read_csv("http://dicook.github.io/Monash-R/data/rates.csv")
rates[1:5,1:8]
#> Source: local data frame [5 x 8]
#> 
#>         date      AED      AFN      ALL     AMD     ANG      AOA      ARS
#>       (date)    (dbl)    (dbl)    (dbl)   (dbl)   (dbl)    (dbl)    (dbl)
#> 1 2015-02-23 3.672900 57.33792 123.8969 478.692 1.78968 105.9075 8.702166
#> 2 2015-02-24 3.672069 57.35200 123.7132 478.608 1.78958 106.1014 8.696728
#> 3 2015-02-25 3.673324 57.32655 123.5259 478.616 1.78954 106.1913 8.715239
#> 4 2015-02-26 3.673028 57.52745 124.5801 480.294 1.78956 106.3042 8.720107
#> 5 2015-02-27 3.672648 57.33172 124.8491 478.812 1.78958 106.3389 8.721236

If you'd like to collect exchange rates yourself, see here.

Plotting points

qplot(date, AUD, data=rates)

Adding lines

qplot(date, AUD, data=rates, geom="line")

Points and lines

qplot(date, AUD, data=rates, geom=c("line", "point"))