tidyverse notes I

What does + geom_*() mean?

ggplot(iris, mapping=aes(x=Sepal.Length, y=Sepal.Width)) +
  geom_point()

is a shortcut to

ggplot(iris, mapping=aes(x=Sepal.Length, y=Sepal.Width)) +
  layer(geom="point", stat="identity", position="identity")
  • Usage of layer()

    layer(
      geom = NULL,
      stat = NULL,
      data = NULL,
      mapping = NULL,
      position = NULL,
      params = list(),
      inherit.aes = TRUE,
      check.aes = TRUE,
      check.param = TRUE,
      show.legend = NA,
      key_glyph = NULL,
      layer_class = Layer
    )
    
  • Component and Defaults in ’layer'

    • Besides data and aesthetic mapping, there are 3 basic components, geom, stat and position.
    • The default settings1:
    geomUseful stats (default in bold)Default position adjustmentParameters (when used with given stat)
    blankidentityidentityno parameters
    ablineablineidentityslope, intercept, size, linetype, colour, alpha
    identityidentityslope, intercept, size, linetype, colour, alpha
    hlinehlineidentityyintercept, size, linetype, colour, alpha
    identityidentityy, yend, size, linetype, colour, alpha
    vlinevlineidentityxintercept, size, linetype, colour, alpha
    identityidentityx, xend, size, linetype, colour, alpha
    textidentityidentityx, y, label, size, colour, alpha, hjust, vjust, parse
    pointidentityidentityx, y, size, shape, colour, fill, alpha, na.rm
    jitteridentityjitterx, y, size, shape, colour, fill, alpha, na.rm
    segmentidentityidentityx, xend, y, yend, size, linetype, colour, alpha, arrow
    lineidentityidentitygroup, x, y, size, linetype, colour, alpha, arrow
    baridentitystackx, y, size, linetype, colour, fill, alpha, weight(?) ???
    binstackx, y, size, linetype, colour, fill, alpha, weight(?) ???
    histogramalias for geom_bar
    areaidentitystackgroup, x, y, size, linetype, colour, fill, alpha, na.rm
    ribbonidentityidentitygroup, x, ymin, ymax, size, linetype, colour, fill, alpha, na.rm
    linerangeidentityidentityx, ymin, ymax, size, linetype, colour, alpha
    pointrangeidentityidentityx, y, ymin, ymax, size, shape, linetype, colour, fill, alpha
    errorbaridentityidentityx, ymin, ymax, size, linetype, colour, alpha, width
    errorbarhidentityidentityx, xmin, xmax, y, size, linetype, colour, alpha, height
    crossbaridentityidentityx, y, ymin, ymax, size, linetype, colour, fill, alpha, width, fatten
    boxplotidentitydodgex, ymin, lower, middle, upper, ymax, size, colour, fill, alpha, weight(?), width(?), outliers(?), outlier.size, outlier.shape, outlier.colour ???
    boxplotdodgex, ymin, lower, middle, upper, ymax, size, colour, fill, alpha, weight(?), width(?), outliers(?), outlier.size, outlier.shape, outlier.colour ???
    pathidentityidentitygroup, x, y, size, linetype, colour, alpha, na.rm, arrow, linemitre, linejoin, lineend
    polygonidentityidentitygroup, x, y, size, linetype, colour, fill, alpha
    rectidentityidentityxmin, xmax, ymin, ymax, size, linetype, colour, fill, alpha
    rugidentityidentityx, y, size, linetype, colour, alpha
    stepidentityidentitygroup, x, y, size, linetype, colour, alpha, direction
    bin2didentityidentityxmin, xmax, ymin, ymax, size, linetype, colour, fill, alpha, weight(?) ???
    bin2didentityxmin, xmax, ymin, ymax, size, linetype, colour, fill, alpha, weight(?) ???
    tileidentityidentityx, y, size, linetype, colour, fill, alpha
    hexidentityidentityx, y, size, colour, fill, alpha
    binhexidentityx, y, size, colour, fill, alpha
    densityidentityidentitygroup, x, y, size, linetype, colour, fill, alpha, weight(?) ???
    densityidentitygroup, x, y, size, linetype, colour, fill, alpha, weight(?) ???
    density2didentityidentitygroup, x, y, size, linetype, colour, alpha, weight(?), na.rm, arrow, linemitre, linejoin, lineend ???
    density2didentitygroup, x, y, size, linetype, colour, alpha, weight(?), na.rm, arrow, linemitre, linejoin, lineend ???
    contouridentityidentitygroup, x, y, size, linetype, colour, alpha, weight(?), na.rm, arrow, linemitre, linejoin, lineend ???
    contouridentitygroup, x, y, size, linetype, colour, alpha, weight(?), na.rm, arrow, linemitre, linejoin, lineend ???
    freqpolyidentityidentitygroup, x, y, size, linetype, colour, alpha, weight(?) ???
    binidentitygroup, x, y, size, linetype, colour, alpha, weight(?) ???
    quantileidentityidentitygroup, x, y, size, linetype, colour, alpha, na.rm, arrow, linemitre, linejoin, lineend
    quantileidentitygroup, x, y, size, linetype, colour, alpha, weight, quantiles, formula, xseq, method, na.rm, arrow, linemitre, linejoin, lineend
    smoothidentityidentitygroup, x, y, ymin, ymax, size, linetype, colour, fill, alpha
    smoothidentitygroup, x, y, size, linetype, colour, fill, alpha, weight
  • Annotations (a special type of layer)

    Annotations don’t inherit global settings from the plot. They are used to add fixed reference data to plots.


Last modified on 2023-11-01