The world of data visualization
DATA VISU AL IZATION IN R
Ron Pearson
Instructor
The w orld of data v is u ali z ation DATA VISU AL IZATION IN R - - PowerPoint PPT Presentation
The w orld of data v is u ali z ation DATA VISU AL IZATION IN R Ron Pearson Instr u ctor Graphical tools help u s u nderstand a dataset O u r abilit y to interpret pa erns is a ke y strength T w o basic t y pes of data v is u ali z ations :
DATA VISU AL IZATION IN R
Ron Pearson
Instructor
DATA VISUALIZATION IN R
Our ability to interpret paerns is a key strength Two basic types of data visualizations: Exploratory visualizations help us understand the data Explanatory visualizations help us share our understanding with others R supports both types of visualizations
DATA VISUALIZATION IN R
Helps you see what is in your data Level of detail: Keep as much detail as possible Practical limit: How much can you see and interpret?
DATA VISUALIZATION IN R
# Exploratory plot of ChickWeight data frame plot(ChickWeight)
DATA VISUALIZATION IN R
Shows others what you’ve found in your data Requires editorial decisions: Highlight the key features you want to emphasize Eliminate extraneous details
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
Base graphics: Easiest to learn and focus of this course Grid graphics: powerful set of modules for building other tools Laice graphics: general purpose system based on grid graphics
ggplot2 : the grammar of graphics
DATA VISUALIZATION IN R
library(MASS) plot(UScereal$sugars, UScereal$Calories) title("plot(UScereal$sugars, UScereal$calories)")
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
# Get the data and load the grid package library(MASS) x <- UScereal$sugars y <- UScereal$calories library(grid) # This is the grid code required to generate the plot pushViewport(plotViewport()) pushViewport(dataViewport(x, y)) grid.rect() grid.xaxis() grid.yaxis() grid.points(x, y) grid.text("UScereal$calories", x = unit(-3, "lines"), rot = 90) grid.text("UScereal$sugars", y = unit(-3, "lines"), rot = 0) popViewport(2)
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
library(MASS) library(lattice) xyplot(MPG.city ~ Horsepower | Cylinders, data = Cars93)
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
library(MASS) library(ggplot2) title <- "ggplot2 plot of \n UScereal$calories vs. \n UScereal$sugars" basePlot <- ggplot(UScereal, aes(x = sugars, y = calories)) basePlot + geom_point(shape = as.character(UScereal$shelf), size = 3) + annotate("text", label = title, x = 3, y = 400, colour = "red")
DATA VISUALIZATION IN R
DATA VISU AL IZATION IN R
DATA VISU AL IZATION IN R
Ron Pearson
Instructor
DATA VISUALIZATION IN R
library(MASS) plot(Boston$rm, Boston$medv, main = "Scatterplot")
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
library(MASS) sunflowerplot(Boston$rad, Boston$tax, main = "Sunflowerplot")
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
library(MASS) boxplot(crim ~ rad, data = Boston, log = "y", las = 1 main = "Boxplot", xlab = "rad", ylab = "crim")
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
mosaicplot(cyl ~ gear, data = mtcars, main = "Mosaicplot")
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
High level functions like plot() Features can be added to a plot The points() function adds points The lines() function adds lines, usually curved The text() function adds labels Using dierent colors - Chapter 5 covers this in detail
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
The par() function sets many graphic parameters One useful parameter is mfrow , which sets up plot arrays This is discussed in Chapter 4
DATA VISUALIZATION IN R
DATA VISUALIZATION IN R
DATA VISU AL IZATION IN R