# Homework 5, STAT 542 # Chapter 8 exercises: # Problems 1, 2, 5, 8, 9 # No R needed for these. # Chapter 14, Problem 3: library(tidyverse); library(mdsr) library(lubridate) example <- c("2015-03-20 18:45:00", "2015-06-21 12:38:00", "2015-09-23 04:21:00", "2015-12-21 23:48:00") converted <- ymd_hms(example) # install.packages("macleish") library(macleish) head(whately_2015) ch14p3 <- ggplot(data = whately_2015, aes(x = when, y = temperature)) + geom_line(color = "darkgray") + xlab(NULL) + ylab("Temperature (degrees Celsius)") + geom_vline(xintercept = converted[1]) + annotate( "text", x = converted[1], y = 25, label = "Vernal equinox", hjust = "left" ) + geom_vline(xintercept = converted[2]) + annotate( "text", x = converted[2], y = -10, label = "Summer Solstice", hjust = "right" ) + geom_vline(xintercept = converted[3]) + annotate( "text", x = converted[3], y = -5, label = "Autumnal equinox", hjust = "left" ) + geom_vline(xintercept = converted[4]) + annotate( "text", x = converted[4], y = 25, label = "Winter Solstice", hjust = "right" ) ch14p3 # A little extra credit (one way to do it): ch14p3 + annotate( "text", x = converted[1], y = 34, color="blue", label = "WINTER", hjust = "right", size=8 ) + annotate( "text", x = converted[2], y = 34, color="green", label = "SPRING", hjust = "right", size=9 )+ annotate( "text", x = converted[3], y = 34, color="red", label = "SUMMER", hjust = "right", size=8 )+ annotate( "text", x = converted[4], y = 34, color="brown", label = "FALL", hjust = "right", size=10 ) # Chapter 14, Problem 6: # install.packages('AER') library(AER) # install.packages('ggExtra') library(ggExtra) data(HousePrices) p <- ggplot(HousePrices, aes(x = lotsize, y = price)) + geom_point() + theme_classic() + stat_smooth(method = "loess", formula = y ~ x, size = 2) ggExtra::ggMarginal(p, type = "histogram", binwidth = 3) # Chapter 14, Problem 7: library(tidyverse); library(mdsr) library(shiny) # install.packages("palmerpenguins") library(palmerpenguins) head(penguins) # See ui.R and server.R files for this problem, and run them by something like: source("Z:/Z from MATHSTAT/My Documents/teaching/stat_542/ch14pr7_Shiny_app/ui.R") source("Z:/Z from MATHSTAT/My Documents/teaching/stat_542/ch14pr7_Shiny_app/server.R") runApp("Z:/Z from MATHSTAT/My Documents/teaching/stat_542/ch14pr7_Shiny_app")