STAT 451, Day 14

More Tools to Visualize Data

More on Plotting Maps in R

There are many libraries that are useful to make maps in R.

When working with maps you will start to use shape files. These are .shp files.

Try to make the plot described on this Playing with R blog post, plotting Bay Area zip codes and income. Shape file is here.

More Graphs in R

From the Quick-R website.

Advanced Graphs

Try some plots using ggplot2

Some R Code

# ggplot2 examples
library(ggplot2) 

# create factors with value labels 
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
    labels=c("3gears","4gears","5gears")) 
mtcars$am <- factor(mtcars$am,levels=c(0,1),
    labels=c("Automatic","Manual")) 
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),
    labels=c("4cyl","6cyl","8cyl"))

More R Code

# Kernel density plots for mpg
# grouped by number of gears 
# (indicated by color)
qplot(mpg, data=mtcars, geom="density", 
   fill=gear, alpha=I(.5), 
   main="Distribution of Gas Milage", xlab="Miles Per Gallon", 
   ylab="Density")

plot of chunk unnamed-chunk-2