Remember that for a Markdown to run, every step of the code must be intact, including reading in data, requiring packages, and assigning data types (such as date columns). Do so in the R-chunk below before moving on to questions 11-15
# read in csv file
weather <- read.csv("weather.csv")
# require r packages
require(tidyverse)
# assign proper date column
weather$date <- ymd(weather$date)
Using R’s base plotting package in the R-chunk below, create a histogram that displays the distribution of precipitation, labeling the x-axis with units, and providing a main title. Change the color so the bins are green.
Preceptor rubric
hist(weather$prcp,
col = "green",
main = "Distribution of Precipitation",
xlab = "Daily Total Precipitation (Inch)")
Using ggplot2 in the R-chunk below, create a histogram that displays the distribution of precipitation, labeling the x-axis within units, providing the main title, and changing the fill of the histogram to be “hotpink”.
Preceptor rubric
ggplot(weather, aes(x = prcp))+
geom_histogram(fill = "hotpink", color = "black")+
labs(x = "Daily Total Precipitation (Inch)",
y = "Count",
title = "Distribution of Precipitation")
#I added/modified the label for the y axis because the existing label was lower case. The only thing I did was make it uppercase.
Using R’s base plotting package in the R-chunk below, create a scatterplot with the maximum temperature in degrees Fahrenheit on the x-axis and the wind speed in MPH on the y-axis. Format the axis labels and main title to have functional names.
Preceptor rubric
plot(weather$tmax,
weather$wind_speed,
xlab = "Max Daily Temperature (F)",
ylab = "Avg. Daily Wind Speed (Mph)",
main = "Relationship of Max Temp and Wind Speed")
Using ggplot2 in the R-chunk below, create a scatterplot with the minimum temperature in degrees F on the x-axis and the wind speed in MPH on the y-axis. Color the points by weather station location. Format the axis labels (including units) and main title to have a short, functional name.
Preceptor rubric
ggplot(weather, aes(x = tmin,
y = wind_speed,
color = location))+
geom_point(alpha = 0.5)+
labs(x = "Min Daily Temperature (F)",
y = "Avg. Daily Wind Speed (Mph)",
title = "Relationship of Min Temp and Wind Speed")
#Added alpha for ease of viewing
For this last, most complicated graph, we want to look at the relationship between maximum temperature, wind speed, wind direction, and site.
In ggplot2, create a two-faceted graph with a scatterplot facet for each weather station location. They should each have the maximum temperature on the x-axis, and wind speed in mph on the y-axis. Points should be colored by the wind’s cardinal direction (N/E/S/W). Make sure the graph has a meaningful title, and the axes and color legend have formatted labels.
Because we are not using degrees for direction, this should NOT be plotted on with a polar coordinates.
Preceptor rubric
ggplot(weather, aes(x = tmax,
y = wind_speed,
color = wind_cardinal))+
geom_point(alpha = 0.5)+
facet_grid(row = vars(location))+
labs(x = "Daily Max Temperature (F)",
y = "Avg. Daily Wind Speed (Mph)",
color = "Direction",
title = "Relationship of Max Temp, Wind Speed, Wind Direction, and Site")