04.10.2018

ggplot2

Эллочка-людоедка

Grammar of Graphics

Hadley Wickham

Basics of Grammar of Graphics and ggplot2

  • Everything is a layer
  • aestetics - aes()

“Aesthetics, in the original Greek sense, offers principles for relating sensory attributes (color, shape, sound, etc.) to abstractions.”

  • Geometries (geoms)
  • Statistics
  • Coordinate systems and scales

Example: Pie-chart

library("ggplot2")
pie <- ggplot(data = da)
pie

Example: Pie-chart

pie <- pie +
  geom_bar(width = 1, position = "fill", color = "black", aes(x = "", fill = factor(Gender)))
pie

Example: Pie-chart

pie + coord_polar(theta = "y")

Example: Pie-chart

pie + coord_polar(theta = "y")+theme_void()

It was not so easy!

ggplot2 extensions

plotly

plotly

  • Dynamic visualization
  • Using d3.js

Example: scatterplot

library(plotly)
data(diamonds)
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
gg <- ggplot(data = diamonds)+
  geom_point(aes(x = carat, y = price, colour = price), alpha = 0.1)
gg

Example: scatterplot

ggplotly(gg)

Example: scatterplot

plot_ly(diamonds, x = ~carat, y = ~price, color = ~carat, size = ~carat)

Other html-widgets

Thank you!