+ - 0:00:00
Notes for current slide
Notes for next slide

Grammar of Graphics

drawing

2/10

Grammar of Graphics

drawing

  • Data: Input data
  • Geom: A geometry representing data. Points, Lines etc
  • Aesthetics: Visual characteristics of the geometry. Size, Color, Shape etc
  • Scale: How visual characteristics are converted to display values
  • Statistics: Statistical transformations. Counts, Means etc
  • Coordinates: Numeric system to determine position of geometry. Cartesian, Polar etc
  • Facets: Split data into subsets
2/10

Building a graph

drawing

3/10

Build-Demo

ggplot(iris)

4/10

Build-Demo

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

5/10

Build-Demo

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

6/10

Build-Demo

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

7/10

Geoms

drawing

8/10

Geoms

drawing

p <- ggplot(iris)
# scatterplot
p+geom_point(aes(x=Sepal.Length,y=Sepal.Width))
# barplot
p+geom_bar(aes(x=Sepal.Length))
# boxplot
p+geom_boxplot(aes(x=Species,y=Sepal.Width))
# search
help.search("^geom_",package="ggplot2")
8/10

Aesthetics

  • Aesthetic mapping vs aesthetic parameter
ggplot(iris)+
geom_point(aes(x=Sepal.Length,
y=Sepal.Width,
size=Petal.Length,
alpha=Petal.Width,
shape=Species,
color=Species))

9/10

Aesthetics

  • Aesthetic mapping vs aesthetic parameter
ggplot(iris)+
geom_point(aes(x=Sepal.Length,
y=Sepal.Width,
size=Petal.Length,
alpha=Petal.Width,
shape=Species,
color=Species))

ggplot(iris)+
geom_point(aes(x=Sepal.Length,
y=Sepal.Width),
size=2,
alpha=0.8,
shape=15,
color="steelblue")

9/10

Multiple geoms

ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+
geom_point()+
geom_line()+
geom_smooth()+
geom_rug()+
geom_step()+
geom_text(data=subset(iris,iris$Species=="setosa"),aes(label=Species))

10/10

Thank you. Questions?

R version 4.1.3 (2022-03-10)

Platform: x86_64-pc-linux-gnu (64-bit)

OS: Ubuntu 22.04.3 LTS



Built on : 02-Feb-2024 at 11:06:13

2024SciLifeLabNBIS

10/10

Grammar of Graphics

drawing

2/10
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow