Statistical Computing 1, Stat 590 Fall 2015
Transcrição
Statistical Computing 1, Stat 590 Fall 2015
Statistical Computing 1, Stat 590 Fall 2015 Name: Answer Key Prof. Erik B. Erhardt Homework 03 Part I. (60 points) Do all calculations in LATEX + R + knitr. For this assignment, all R code should well commented and be visible (echo=TRUE) in the document where you have written it. Every time you create or modify an object, please show the results with the appropriate function. Please do not display complete objects when they are large. Weather data: This is an exercise in manipulating data. We will be using daily weather data from the Albuquerque International Airport (KABQ). (30pts ) 1. Read and manipulate (a) (10 pts) Read in the data directly from the KABQ weather website: http://www. wunderground.com/, history, KABQ, date rante, etc. Solution: fn.list <- c( "http://www.wunderground.com/history/airport/KABQ/2009/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2009&r , "http://www.wunderground.com/history/airport/KABQ/2010/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2010&r , "http://www.wunderground.com/history/airport/KABQ/2011/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2011&r , "http://www.wunderground.com/history/airport/KABQ/2012/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2012&r , "http://www.wunderground.com/history/airport/KABQ/2013/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2013&r , "http://www.wunderground.com/history/airport/KABQ/2014/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2014&r , "http://www.wunderground.com/history/airport/KABQ/2015/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2015&r ) # list to hold all the data files all.dat <- as.list(new.env()) # read all data for (i.dat in 1:length(fn.list)) { # read each year's data dat.temp <- read.csv( fn.list[i.dat] , stringsAsFactors = FALSE ) # put data into it's own list all.dat[[i.dat]] <- dat.temp } # all the column names match except for the last data.frame colnames(all.dat[[1]]) == colnames(all.dat[[7]]) ## [1] FALSE ## [12] TRUE ## [23] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE # change that column name to match the others colnames(all.dat[[7]])[1] <- "MST" # combine all data together into one data.frame dat <- do.call("rbind", all.dat) str(dat) ## 'data.frame': 2441 obs. of ## $ MST ## $ Max.TemperatureF ## $ Mean.TemperatureF 23 variables: : chr "2009-1-1" "2009-1-2" "2009-1-3" "2009-1-4" ... : int 56 57 57 42 40 41 49 57 54 46 ... : int 42 43 44 34 31 34 36 43 41 37 ... SC1/HW03 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## – Page 2 of 6 – $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Min.TemperatureF : Max.Dew.PointF : MeanDew.PointF : Min.DewpointF : Max.Humidity : Mean.Humidity : Min.Humidity : Max.Sea.Level.PressureIn : Mean.Sea.Level.PressureIn: Min.Sea.Level.PressureIn : Max.VisibilityMiles : Mean.VisibilityMiles : Min.VisibilityMiles : Max.Wind.SpeedMPH : Mean.Wind.SpeedMPH : Max.Gust.SpeedMPH : PrecipitationIn : CloudCover : Events : WindDirDegrees.br... : int int int int int int int num num num int int int int int int chr int chr chr Name: Answer Key 28 28 31 25 21 27 23 28 27 28 ... 23 21 26 28 23 23 23 25 26 23 ... 20 19 19 17 16 18 20 23 23 16 ... 18 15 16 6 10 14 17 21 17 11 ... 69 69 53 70 68 69 69 69 75 69 ... 47 45 37 55 53 52 53 50 54 47 ... 24 20 20 39 37 34 36 30 32 25 ... 30.1 30 29.9 30.2 30.2 ... 30 29.9 29.8 30 30 ... 29.9 29.7 29.7 29.8 29.8 ... 10 10 10 10 10 10 10 10 10 10 ... 10 10 10 9 10 10 10 10 10 10 ... 10 10 10 2 10 10 10 10 10 10 ... 10 9 22 36 22 25 22 14 23 18 ... 3 3 7 18 5 14 10 6 8 7 ... 14 12 29 43 29 33 29 17 29 25 ... "0.00" "0.00" "0.00" "T" ... 1 1 4 7 6 4 4 1 3 2 ... "" "" "" "Snow" ... "27<br />" "119<br />" "298<br />" "77<br />" ... (b) (5 pts) Create a date column from the MST column (should be in POSIXct format). Use as.Date() or a function from the lubridate package. Solution: library(lubridate) dat$Date <- ymd(dat$MST) str(dat[, c("MST", "Date")]) ## 'data.frame': 2441 obs. of 2 variables: ## $ MST : chr "2009-1-1" "2009-1-2" "2009-1-3" "2009-1-4" ... ## $ Date: POSIXct, format: "2009-01-01" ... (c) (10 pts) Create (numeric) month and year columns from the MST column. Use ?sub and try of the examples there; also, google “regular expression R” for more info. Or try package stringr and function str_split() and rbind(). Solution: library(stringr) # the result of spliting the strings is a list of lists dat.ymd <- str_split(dat$MST, "-") head(dat.ymd) ## [[1]] ## [1] "2009" "1" "1" ## ## [[2]] ## [1] "2009" "1" "2" ## ## [[3]] ## [1] "2009" "1" "3" SC1/HW03 ## ## ## ## ## ## ## ## ## – Page 3 of 6 – [[4]] [1] "2009" "1" "4" [[5]] [1] "2009" "1" "5" [[6]] [1] "2009" "1" "6" Name: Answer Key # bind the lists together using rbind dat.ymd <- do.call("rbind", str_split(dat$MST, "-")) head(dat.ymd) ## ## ## ## ## ## ## [1,] [2,] [3,] [4,] [5,] [6,] [,1] "2009" "2009" "2009" "2009" "2009" "2009" [,2] "1" "1" "1" "1" "1" "1" [,3] "1" "2" "3" "4" "5" "6" dat.ymd <- data.frame(Year = dat.ymd[,1], Month = dat.ymd[,2], stringsAsFactors = FALSE) str(dat.ymd) ## 'data.frame': 2441 obs. of 2 variables: ## $ Year : chr "2009" "2009" "2009" "2009" ... ## $ Month: chr "1" "1" "1" "1" ... # combine all data together into one data.frame dat <- cbind(dat, dat.ymd) # order the date factor variables dat$Year <- factor(dat$Year) dat$Month <- factor(dat$Month, levels = 1:12, labels = as.character(1:12), ordered = TRUE) (d) (5 pts) Replace all occurances of T with 0 in the PrecipitationIn column make convert to a numeric variable using as.numeric(). Solution: str(dat$PrecipitationIn) ## chr [1:2441] "0.00" "0.00" "0.00" table(dat$PrecipitationIn) ## ## 0.00 0.01 0.02 0.03 0.04 0.05 0.06 ## 1744 56 40 21 26 20 7 ## 0.14 0.15 0.16 0.17 0.18 0.19 0.20 ## 9 5 5 1 3 4 5 ## 0.28 0.29 0.31 0.32 0.34 0.35 0.37 ## 2 1 2 2 2 1 1 ## 0.51 0.52 0.56 0.57 0.58 0.59 0.60 ## 2 1 2 2 1 1 1 ## 0.98 1.06 1.22 1.36 1.77 1.82 T ## 1 1 1 1 1 1 349 # replace "T" with 0 "T" "0.00" "0.00" ... 0.07 9 0.21 3 0.38 2 0.63 1 0.08 17 0.22 4 0.41 2 0.66 1 0.09 9 0.23 3 0.42 3 0.69 2 0.10 12 0.24 4 0.43 1 0.75 1 0.11 15 0.25 5 0.44 1 0.85 1 0.12 7 0.26 3 0.46 1 0.91 1 0.13 6 0.27 2 0.50 1 0.96 2 SC1/HW03 – Page 4 of 6 – Name: Answer Key dat$PrecipitationIn[(dat$PrecipitationIn == "T")] <- 0 # change to numeric dat$PrecipitationIn <- as.numeric(dat$PrecipitationIn) str(dat$PrecipitationIn) ## (30pts ) num [1:2441] 0 0 0 0 0 0 0 0 0 0 ... 2. Subset and plot (a) (10 pts) Use subset to keep only the columns related to the dates (including those created above), and mean precipitation, temperature, and wind. Solution: # subset data dat.sub <- subset(dat, select = c("Mean.TemperatureF" , "Mean.Wind.SpeedMPH" , "PrecipitationIn" , "Date" , "Year" , "Month" )) str(dat.sub) ## 'data.frame': 2441 obs. of 6 variables: ## $ Mean.TemperatureF : int 42 43 44 34 31 34 36 43 41 37 ... ## $ Mean.Wind.SpeedMPH: int 3 3 7 18 5 14 10 6 8 7 ... ## $ PrecipitationIn : num 0 0 0 0 0 0 0 0 0 0 ... ## $ Date : POSIXct, format: "2009-01-01" ... ## $ Year : Factor w/ 7 levels "2009","2010",..: 1 1 1 1 1 1 1 1 1 1 ... ## $ Month : Ord.factor w/ 12 levels "1"<"2"<"3"<"4"<..: 1 1 1 1 1 1 1 1 1 1 ... (b) (10 pts) Use the melt() function to transform the subsetted object from wide form into long form. What are the id.vars here? Solution: library(reshape2) dat.sub.long <- melt(dat.sub, id.vars = c("Date", "Year", "Month")) str(dat.sub.long) ## 'data.frame': 7323 obs. of 5 variables: ## $ Date : POSIXct, format: "2009-01-01" ... ## $ Year : Factor w/ 7 levels "2009","2010",..: 1 1 1 1 1 1 1 1 1 1 ... ## $ Month : Ord.factor w/ 12 levels "1"<"2"<"3"<"4"<..: 1 1 1 1 1 1 1 1 1 1 ... ## $ variable: Factor w/ 3 levels "Mean.TemperatureF",..: 1 1 1 1 1 1 1 1 1 1 ... ## $ value : num 42 43 44 34 31 34 36 43 41 37 ... (c) (10 pts) Create a plot of the measured variables over time using geom_point() and facet_wrap(, scales = ). Organize your facets (small multiples) so they are easily comparible. Solution: SC1/HW03 – Page 5 of 6 – Name: Answer Key library(ggplot2) p <- ggplot(dat.sub.long, aes(x = Date, y = value)) p <- p + geom_point() p <- p + facet_wrap( ~ variable, ncol = 1, scales = "free_y") print(p) ## Warning: ## Warning: Removed 1 rows containing missing values (geom point). Removed 1 rows containing missing values (geom point). Mean.TemperatureF 75 50 25 ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ●● ● ●● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●●●● ● ● ●● ● ● ● ● ●● ● ●● ● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ●● ● ● ●● ● ●● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ●● ● ●● ●● ●● ●● ● ● ● ● ● ●● ● ● ● ● ●● ●●● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ●● ● ● ●● ●●●● ●● ● ● ●● ●●● ● ● ● ● ●●● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●●●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ● ● ●●● ● ●● ● ● ● ● ● ●●● ● ● ●● ●●● ●● ●● ●● ●● ● ● ●● ● ● ●● ●●● ● ●●● ● ●● ● ● ● ● ● ● ●● ●● ● ●● ● ● ● ● ● ●● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●● ●● ● ●●●● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ●●● ● ● ●● ● ●● ● ● ● ● ● ●●●● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ●● ● ● ●● ●● ●● ●● ● ● ●● ● ● ● ● ●●●● ●● ● ● ● ●● ● ● ● ●● ● ●●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ●●●● ● ●● ●● ● ● ●● ● ● ● ● ●●●●● ● ● ●● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ● ●●● ●●● ●● ●●● ●●● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ●● ●●● ●● ●● ● ● ● ●●●● ● ●● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ●●● ●●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ●●●●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●●● ● ●● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ●● ● ● ● ●● ●● ● ● ● ●●● ● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ●● ● ●● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● Mean.Wind.SpeedMPH ● 30 value 20 10 0 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ●● ●● ● ● ● ●● ●●● ● ● ● ● ● ● ●● ●● ●● ● ● ● ●●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ●● ●● ●●●● ●●● ● ● ● ● ●● ● ● ● ● ●●●●● ●●● ● ● ●● ● ●● ● ● ●● ●●●● ●● ● ● ● ● ● ● ●● ● ●● ●● ●● ● ● ●●● ● ●● ●● ● ●● ● ●●● ● ●●● ●●●●● ● ● ●● ● ●● ● ● ● ● ● ● ●● ●● ● ●● ● ●● ● ● ● ● ● ●● ● ●●●●●● ● ● ● ● ●● ●● ●● ● ●● ● ● ●●●● ●● ● ●● ● ● ●● ● ●● ● ●●● ●● ● ●● ●●●● ●● ● ●● ●●●●●● ● ● ● ● ● ● ● ●● ●● ●●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ●●● ● ● ● ●●● ● ● ●● ● ● ●●●●●● ●● ● ● ● ● ● ●● ●●● ●● ● ● ●●●●●● ●●● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ●● ● ● ● ● ●● ● ● ●●● ●● ● ● ●● ●● ● ●● ● ● ● ●● ● ●●● ● ● ●● ● ● ● ●● ●●● ●●●●●● ● ●●● ● ● ● ●●●● ● ●●● ●● ● ●● ●●● ● ●● ● ● ●● ●●● ●● ●●●●●●●● ●●● ● ● ●● ●●● ●● ●● ●●● ● ●● ● ●●●● ● ●●●●● ● ● ● ● ●●●●●● ● ●● ● ●● ● ● ● ●● ●●● ●●●●●● ●● ● ●●● ● ●● ●● ●● ●● ●● ●● ● ●● ●● ● ●● ● ● ● ● ● ●● ●● ● ● ●●● ● ● ● ●● ● ● ●● ●●● ●●● ● ●●● ●●● ● ● ● ●● ● ● ● ● ●●●●●●● ● ●●●● ●● ●●● ● ● ●● ● ● ● ●● ●●● ● ● ●● ● ● ●●●● ● ●● ●● ●●●●● ●●●● ●● ● ●●● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ●●●●●●● ●●●● ●● ● ● ● ●●●● ●●● ● ● ●●●●● ●● ● ●● ●● ● ●● ● ●● ●● ● ● ●●● ●● ● ● ● ●●●●● ●●●●●●● ● ●●●● ●● ● ● ●●●●● ● ●● ●●●● ● ●● ●● ● ●●●●●● ●●● ● ●●●●● ● ● ●● ●● ●●●●● ● ● ●● ● ● ● ● ●● ●●● ●● ●●●● ●●● ● ●●● ●●● ● ●● ●● ●● ● ● ● ● ● ●●● ● ● ● ●●● ●● ● ●●●● ● ● ● ● ● ● ●● ●● ● ●● ●●● ● ●●●● ●●● ● ●●●● ● ●●● ● ●● ● ●● ● ● ●●●● ● ● ●● ● ● ●● ●● ●● ● ● ●● ● ●●● ● ●● ● ● ● ● ● ●●●●● ● ●●● ●● ● ● ●● ●●●● ● ●●●● ● ● ● ●●● ● ● ●●● ●●● ● ● ●●● ● ●● ● ● ●● ● ●● ●● ● ● ●●● ●● ●● ● ●● ●● ● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ●● ● ●●● ●● ● ●●● ● ●● ● ●●● ●● ● ●● ● ● ●● ●● ●● ● ●●● ● ● ●● ●●●● ● ● ●●●●● ● ● ●● ●●● ● ●●● ●●● ●● ● ● ● ● ● ●● ● ●●● ●●● ● ●●● ● ● ● ●●●● ● ●● ● ●● ● ● ●● ● ● ● ● ● ●● ●●● ●●●●●●●● ●●● ●● ●●●● ●● ● ● ●● ● ●● ● ●● ● ●● ●● ●● ● ● ● ● ●● ● ●● ● ●● ●● ●● ● ● ●●● ●●●● ● ● ●● ●●● ● ● ●● ●●●● ● ● ● ● ●● ● ●● ●● ● ● ●●● ●●● ● ●● ● ● ●●● ● ●●●●●● ● ● ● ●● ●● ●● ● ●● ● ●●●● ●● ● ●● ●●●●● ● ● ● ●●●● ● ● ● ●● ●●●● ●● ●● ●● ●●● ●● ●● ● ●● ●● ● ● ● ● ●● ● ● ● ● ●● ●●●● ● ● ● ● ● ● ● ●● ● ● ● ●● ●●● ●●● ● ● ● ● ●●●● ●● ●● ●● ● ● ●● ● ●● ●●● ● ● ● ● ●● ● ● ●●●●● ●● ●● ● ● ● ● ● ● ● ●●● ● ●● ● ●●● ●● ●●● ●● ● ●● ●● ●● ●●● ●● ●●● ●●● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ●●●● ●●● ●● ● ●● ● ●● ● ● ● ● ● ●●●●● ● ● ● ●●●● ● ● ●● ●●● ●●● ● ●●●●● ● ●●●● ● ● ● ● ● ●●● ● ● ●●●● ●●●● ● ●● ● ●● ● ● ●●●●●● ●●●●● ● ● ●● ● ● ● ●● ●●●●● ●●● ●● ● ●● ●●●●● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ●●● ●● ● ●●● ● ●●●●●●● ●●● ●●● ● ●●●●●● ●● ●● ● ●● ● ●● ●● ● ● ● ●● ● ● ● ●●● ● ●● ● ● ●●●●● ●● ● ●● ● ●● ●● ● ● ● ●● ● ● ●●● ●●●●●● ● ● ●● ●●●● ●● ●● ●●● ● ●●●●● ● ● ●● ●●● ● ●● ●●● ●●● ● ● ● ● ● ● ● ● ●● ●●● ● ● ● ●●●● ● ●●● ● ● ●● ● ● ● ●● ●● ● ● ●● ●● ● ● ●● ● ●●●● ● ●● ● ● ●● ●● ●● ●● ● ● ● ● ● ●● ● ● ● ●● ●● ●● ●● ● ● ● ● ● ● ●● ● ● ●● ●● ● ●●● ●● ●●● ● ● ● ●● ●● ● ● ●●● ● ●●●●● ● ● ● ● ●● ● ● ● ● ● ●●●●● ●●● ●● ●● ● ● ● ●●●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ●●●● ●● ● ● ●● ●● ● ●●● ●●●● ● ●●● ●●● ●●● ● ● ● ●● ● ●● ● ●● ● ●● ● ● ●● ● ●● ● ● ●● ● ● PrecipitationIn ● ● 1.5 ● ● 1.0 0.5 0.0 ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ●● 2010 ● ● ● ● ● ● ● 2012 2014 2016 Date (d) (0 pts) EXTRA +5: Add a local trend line with geom_smooth(), and explain what this does, and improve other aspects of your plot. You’ll see that the the default smoother doesn’t capture the patterns that well. Improve by clicking through the help: follow geom_smooth() to stat_smooth() to the method used, to loess() and the span parameter. Solution: library(ggplot2) p <- ggplot(dat.sub.long, aes(x = Date, y = value)) p <- p + geom_line() # free_y for separate axes p <- p + facet_wrap( ~ variable, ncol = 1, scales = "free_y") # span small to be sensitive to small changes p <- p + geom_smooth(size = 2, method = loess, span = 0.1) print(p) ## ## ## ## Warning: Warning: Warning: Warning: Removed Removed Removed Removed 1 1 1 1 rows rows rows rows containing containing containing containing missing missing missing missing values values values values (stat (stat (geom (geom smooth). smooth). path). path). SC1/HW03 – Page 6 of 6 – Name: Answer Key Mean.TemperatureF 75 50 25 Mean.Wind.SpeedMPH value 30 20 10 0 PrecipitationIn 1.5 1.0 0.5 0.0 2010 2012 2014 Date 2016
Documentos relacionados
IX PADRON BENEF. CUIDAR ABRIL11 .xlsx
YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN YOBAIN ...
Leia mais<a href="http://www.wunderground.com/cgi
target="_blank"> Leia mais