Presentation is loading. Please wait.

Presentation is loading. Please wait.

Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn.

Similar presentations


Presentation on theme: "Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn."— Presentation transcript:

1 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn PowerPoint must be in View Show Mode to See videos and hyperlinks

2 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 2 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn

3 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 3 Making Box, Dot, Histogram, Strip Charts Click video image to start video

4 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 4 Overview of R Charting High Level Plot Functions Arguments Menu TypeR function() Bar Chartbarplot() Box & Whisker Plotboxplot() Dot Plotdotchartt() Histogramhist() Scatter Plotplot() Strip Chartstripchart() High Level Function Arguments type= type = “p” – individual points type = “l” – line type = “b” – points connected with lines type = “h” – vertical lines from 0 type = “s” – step chart xlab = “ “ ylab = “ “ X and Y axis titles main = “ “ sub = “ “ Figure title top of plot, large font Sub title – below X axis, smaller font axes = Tor FSet to F when you want custom axis Produce complete chart

5 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 5 Module 5 Box, Dot, Histogram, Strip Charts Menu Box Plot Dot Plot Histogram Strip Chart

6 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 6 Making a Box & Whisker Plot with boxplot() Function Menu boxplot(Sepal.W ~ Species, data = my_data, col = "grey", horizontal = FALSE, par(cex = 0.7),whisklty=1, outline = TRUE, boxcol = "grey", boxwex = 0.5, border = "darkgrey", pch = 16, outcol = "red", main = Title) "Sepal.L","Sepal.W","Petal.L","Petal.W","Species" 5.1,3.5,1.4,0.2,"setosa“ 4.9,3,1.4,0.2,"setosa“ 4.7,3.2,1.3,0.2,"setosa“ 4.6,3.1,1.5,0.2,"setosa“ 5,3.6,1.4,0.2,"setosa“ 5.4,3.9,1.7,0.4,"setosa" boxplot() boxplot(?? ~ ??, data = ??, col = “??", horizontal = ??, par(cex = 0.??),whisklty=??, outline = ??, boxcol = “??", boxwex = ??, border = “??", pch = ??, outcol = “??, main = ??) Data File: C:\\Learn_R\\Mod_4_R_Charts\\iris_data.txt R’s Iris flower data set copied to text file

7 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 7 Box plot with All Points boxplot(Sepal.L ~ Species, data = my_data, col = "blue", horizontal = FALSE, par(cex = 0.65),whisklty=1, outline = TRUE, boxfill = "grey", boxwex = 0.5, border = "darkgrey", pch = 16, outcex = 1.25, outcol = "red", main = Title) points(my_data$Sepal.L~my_data$Species, pch=16, col="red") R lets you add low level graphics to a plot Show all points on box plot

8 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 8 Assignment 5-1 Make a Box plot Menu Make your own box plot like this Notice horizontal orientation, line style and blue color #################### Box_plot_assign.R ################### ##Script to produce assignment box plot ## STEP 1: SETUP & Source File rm(list=ls()) oldpar<- par(no.readonly=T) par(las=1); par(oma=c(2,4,0,2)); par(mar=c(3,3,3,1)) script <- "C:/Learn_R/Mod_5_box_dot_hist_charts/Practice_5_1_Bo link <- "C:\\Learn_R\\Mod_5_Box_Dot_Hist_Charts\\iris_data.txt" ## STEP 2: READ DATA my_data <- read.table(link, sep = ",", dec=".", skip = 0, row.names = NULL, header = TRUE, colClasses = c(rep("numeric", 4), "factor"), na.strings = c("", "*", "-", -99.99,99.9, 999.9)) ## STEP 3: MANIPULATE DATA Title <- "Iris Flower Data Set: Petal Length" ## STEP 4: CREATE PLOT boxplot(Petal.L ~ Species, data = my_data, col = "blue", horizontal = TRUE, cex = 0.65,whisklty=5, outline = TRUE, boxcol = "grey", boxwex = 0.5, border = "darkgrey", pch = 16, outcex = 1., outcol = "red", main = Title) ## Outer margin annotation my_date <- format(Sys.time(), "%m/%d/%y") mtext(script, side = 1, line =.5, cex=0.7, outer = T, adj = 0) mtext(my_date, side = 1, line =.5, cex = 0.7, outer = T, adj = 1) ## STEP 5: CLOSE par(oldpar)

9 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 9 Making a Dot Plot with dotchart() Function Dot plots developed by William Cleveland Alternative to bar charts X axis displays measurement Y axis displays categorical label Menu Dotchart() dotchart(??, labels = ??, groups = ??, main = “??", xlab = "??", pch = ??, col = "??", lcolor = ??, gcolor = ??) Data File:C:\Learn_R\Mod_5_Box_Dot_Hist_Charts\dot_plot_data.txt

10 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 10 Dot Plot Scripts Simple & Grouped dotchart(Quad_BTU, labels = Fuel, main = Title, xlab = "Quadrillion BTU", pch = 16, col = "blue", lcolor = NULL) text(5,0.5, cex=0.65, pos=4, Source) dotchart(Quad_BTU, labels = Fuel, groups = Type, main = Title, xlab = "Quadrillion BTU", pch = 16, col = "blue", lcolor = NULL, gcolor = “red“ ) text(5,0.5, cex=0.65, pos=4, Source) Simple Dot Plot Grouped Dot Plot Menu

11 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 11 Assignment 5-2 Dot Plot Start with script C:/Learn_R/Mod_5_Box_Dot_Hist_Charts/Dot_plot_Simple_example.R Make your own dot plot like this Use dot_plot_data.txt for source data Notice Y axis grid lines with grey color Menu dotchart(Quad_BTU, labels = Fuel, main = Title, cex = 0.7, xlab = "Quadrillion BTU", pch = 16, col = "blue", lcolor = NULL) text(5,0.5, cex=0.65, pos=4, Source) grid(nx=0, ny=10,col = "grey")

12 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 12 Making a Histogram with hist() Function Menu hist(my_scores, freq = T, breaks = 10,border="black", labels=T, xlim = c(8, 20), ylim = c(0,12), col = "darkgrey", xlab = "Exam Score", ylab= "Number of Students",cex.main=t_par, main = "Histogram of Exam Results: \n Score out of possible 20 points") axis(1, at=seq(8, 20, 1))

13 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 13 Making a Histogram with hist() Function Enhancing a histogram: –Histogram w/ counts –Distribution –Median line –Counts <> Median –Summary Stats in Note Menu

14 Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 14 Making a Strip Chart with stripchart() Function stripchart(Sepal.L ~ Species, data = my_data, col = "grey", main = Title, font.main=2, vertical = T, pch = 16, font.axis = 1,cex=1., cex.main = 1.2, cex.axis = 1.1)


Download ppt "Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn."

Similar presentations


Ads by Google