CSC 360 Module 5 Lecture Notes

Harold Nelson

April 14, 2016

library(ggplot2)

Scatterplots in base and ggplot2

plot(iris$Sepal.Width,iris$Petal.Length,main="base Version")

ggplot(data = iris,aes(x=Sepal.Width,y=Petal.Length)) +
  geom_point() +
  ggtitle("ggplot2 Version")

Enhance Scatterplots in ggplot2 with aesthestics

#qplot(Sepal.Width,Petal.Length,data=iris,
#      color=Species,main="qplot")
ggplot(data = iris,
       aes(x=Sepal.Width,y=Petal.Length,
           color=Species)) +
  geom_point() +
  ggtitle("ggplot with Color")

#qplot(Sepal.Width,Petal.Length,data=iris,
#      shape=Species,main="qplot")

ggplot(data = iris,
       aes(x=Sepal.Width,y=Petal.Length,
           shape=Species)) +
  geom_point() +
  ggtitle("ggplot with Shape")

Enhance Scatterplots in ggplot2 with facets

ggplot(data = iris,
       aes(x=Sepal.Width,y=Petal.Length,
           color=Species)) +
  geom_point() +
  ggtitle("ggplot with Color and Facet") +
  facet_wrap(~Species)

Aesthestics Examples using mpg from ggplot2

These examples use the simple qplot function available in the ggplot2 package.

qplot(displ,hwy,data=mpg)

qplot(displ,hwy,data=mpg,color=class)