STAT 451, Day 15

More Tools to Visualize Data

Return to setup variables for example

# 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

# Scatterplot of mpg vs. hp for each 
# combination of gears and cylinders
# in each facet, transmition type is 
# represented by shape and color
qplot(hp, mpg, data=mtcars, shape=am, 
   color=am, facets=gear~cyl, size=I(3),
   xlab="Horsepower", ylab="Miles per 
   Gallon") 

plot of chunk unnamed-chunk-2

More R Code

# Separate smoothers of mpg on weight for each number of cylinders
qplot(wt, mpg, data=mtcars, geom=c("point", 
   "smooth"), color=cyl, 
   main="Smoothers of MPG on Weight", 
   xlab="Weight", ylab="Miles per Gallon")

plot of chunk unnamed-chunk-3

More R Code

# Boxplots of mpg by number of gears 
# observations (points) are overlayed and jittered
qplot(gear, mpg, data=mtcars, 
   geom=c("boxplot", "jitter"), 
   fill=gear, main="Mileage by Gear Number",
   xlab="", ylab="Miles per Gallon")

plot of chunk unnamed-chunk-4

D3 in Action

More Packages

More on Financial Data

Wrap up Chapter 3

Does anyone have any particular questions about the following in R?

All run code and include the results from R in the document and can be saved in pdf, html, and posted to RPubs.

R Cheatsheets

  • RStudio Cheatsheets For the IDE, Shiny, Data Visualization, Package Development, Data Wrangling, R Markdown.

Tree Maps

Note that TreeMaps are not maps as we have discussed so far. TreeMaps have been commonly used to make “Maps of the Market.”

Try the TreeMap tutorial.

TreeMap Research

WinDirStat

FinViz