ggplot2
basicsDuring ANLY 512 we will be studying the theory and practice of
data visualization. We will be using R
and the
packages within R
to assemble data and construct many
different types of visualizations. We begin by studying some of the
theoretical aspects of visualization. To do that we must appreciate the
basic steps in the process of making a visualization.
The objective of this assignment is to complete and explain basic plots before moving on to more complicated ways to graph data.
A couple of tips, remember that there may be pre-processing involved in your graphics so you may have to do summaries or calculations to prepare, those should be included in your work.
To ensure accuracy pay close attention to axes and labels, you will be evaluated based on the accuracy and expository nature of your graphics. Make sure your axis labels are easy to understand and are comprised of full words with units if necessary.
Each question is worth 5 points.
To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your Rpubs account. Once uploaded you will submit the link to that document on Canvas. Please make sure that this link is hyper linked and that I can see the visualization and the code required to create it.
nasaweather
package, create a
scatter plot between wind and pressure, with color being used to
distinguish the type of storm.nasaweather_storms <- storms
ggplot(storms, aes(x = wind, y = pressure, color = type)) +
geom_point() +
labs(title = "scatter plot between wind and pressure", x = "Wind", y = "Pressure")
MLB_teams
data in the mdsr
package
to create an informative data graphic that illustrates the relationship
between winning percentage and payroll in context.mdsr_MLB_teams <- MLB_teams
ggplot(mdsr_MLB_teams, aes(x = WPct, y = payroll)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(title = "Scatterplot of Winning Percentage vs Payroll", x = "Winning Percentage", y = "Payroll")
RailTrail
data set from the mosaicData
package describes the usage of a rail trail in Western Massachusetts.
Use these data to answer the following questions.volume
against the high temperature that dayweekday
(an indicator
of weekend/holiday vs. weekday)mosaicData_RailTrail <- RailTrail
#a
ggplot(mosaicData_RailTrail, aes(x = volume, y = hightemp)) +
theme_bw() +
geom_point() +
labs(title = "Scatterplot of Volume vs High Temperature", x = "Volume", y = "High Temperature")
#b
ggplot(mosaicData_RailTrail, aes(x = volume, y = hightemp)) +
theme_bw() +
geom_point() +
facet_wrap(~dayType) +
labs(title = "Scatterplot of Volume vs High Temperature", x = "Volume", y = "High Temperature")
#c
ggplot(mosaicData_RailTrail, aes(x = volume, y = hightemp)) +
theme_bw() +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
facet_wrap(~dayType) +
labs(title = "Scatterplot of Volume vs High Temperature", x = "Volume", y = "High Temperature")
nasaweather
package, use the
geom_path
function to plot the path of each tropical storm
in the storms
data table. Use color to distinguish the
storms from one another, and use faceting to plot each year in its own
panel.storms %>%
ggplot(aes(x=lat, y=long))+
geom_path(aes(color = name))+
facet_wrap(~year)
penguins
data set from the
palmerpenguins
package.#a
palmerpenguins_penguins <- penguins
ggplot(palmerpenguins_penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
labs(title = "Scatterplot 1 of Bill Length vs Bill Depth", x = "Bill Length", y = "Bill Depth")
##the association of bill depth and bill length seem linear within each species, as bill length increases, the bill depth increases as well. Plus, the adelie species seem like have similar bill depth to chinstrap but with shorter bill length. Also, Gentoo has similar bill length to chinstrap, but Gentoo has lower bill depth.
#b
ggplot(palmerpenguins_penguins, aes(x = bill_length_mm, y = bill_depth_mm)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
facet_wrap(~species) +
labs(title = "Scatterplot 2 of Bill Length vs Bill Depth", x = "Bill Length", y = "Bill Depth")
#the facet wrap shows that the bill length vs bill depth within each species are somewhat linear.