Grammar of graphics in_exercise 0420

Grammar of graphics in_exercise 0420

  • In_class exercise 1

Chen Meng-ting

In_class exercise 1

This exercise is to compare the differences of commands of R base graphics, trellis graphics and grammar of graphic.

## draw a point of women height against weight on the first-row using R base graphics  
plot(women, type='n')
points(women[1,])

## draw a point of women height against weight on the first-row using trellis graphics.
## type=p means point
lattice::xyplot(weight ~ height,
  data=women,
  subset=row.names(women)==1, type='p')

## draw a point of women height against weight on the first-row using grammar of graphics.
## superimpose geom_point on top of layer "aes".
library(ggplot2)
ggplot(data=women[1,], aes(height, weight))+
  geom_point()