Directions

During 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.

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.

Questions

  1. Using data from the nasaweather package, create a scatter plot between wind and pressure, with color being used to distinguish the type of storm.
storm_data <-nasaweather::storms
storm_data %>%
ggplot(aes(y=wind,x=pressure,color=type))+
  geom_point()+
  labs(y='Wind',x='Pressure',title='Relationship between Wind and Pressure for different types of storms',color='Storm Type',subtitle='As Speed reduces Pressure increases')+
  theme_bw()

  1. Use the MLB_teams data in the mdsr package to create an informative data graphic that illustrates the relationship between winning percentage and payroll in context.
mlb_data<-mdsr::MLB_teams
mlb_data <- mlb_data %>%
  mutate(
  yearID = factor(mlb_data$yearID),
  payroll_M= payroll/1e6
)
mlb_year_pay_avg <-mlb_data %>%
  group_by(yearID) %>%
  summarise(
    year = first(yearID),
    avg_payroll = mean(payroll)
  )
mlb_data %>%
  ggplot(aes(y=WPct,x=payroll_M,color=teamID)) +
  geom_point() +
  facet_wrap(~yearID,) +
  #geom_vline(data=mlb_year_pay_avg,xintercept=mlb_year_pay_avg$avg_payroll) +
  labs(y='Win Percentage',x='Payroll in Millions USD',title='Comparing Win Percentage against Payroll for MLB teams over the years',color='Team')+
  theme_bw()+
  theme(legend.position = "bottom",legend.key.size = unit(0.001,'cm'))

  1. The 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.
  1. Create a scatterplot of the number of crossings per day volume against the high temperature that day
  2. Separate your plot into facets by weekday (an indicator of weekend/holiday vs. weekday)
  3. Add regression lines to the two facets
rail_data <- mosaicData::RailTrail

ggplot(data=rail_data,aes(y=volume,x=hightemp)) +
  geom_point()+
  facet_grid(weekday~.)+
  geom_smooth(method='lm',se=TRUE)+
  labs(y='Volume of Crossings',x='Temperature High in F',title='Crossing Volume by High Temperature of the Day',subtitle='compared across weekday vs weekend')+
  theme_bw()

  1. Using data from the 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.
storm_data$timestamp = lubridate::make_datetime(month=storm_data$month,day=storm_data$day,hour=storm_data$hour,year=storm_data$year)
ggplot(data=storm_data,aes(y=long,x=lat,color=name))+
  geom_path()+
  facet_grid(year~.)+
  labs(title='Path of each storm seperated by year given latitude and longitude',x='Lattitude',y='Longitude',color='Storm Name')+
  theme_bw()+
  theme(legend.position = "right",legend.key.size = unit(0.001,'cm'))

  1. Using the penguins data set from the palmerpenguins package.
  1. Create a scatterplot of bill_length_mm against bill_depth_mm where individual species are colored and a regression line is added to each species. Add regression lines to all of your facets. What do you observe about the association of bill depth and bill length?

We observe that as bill depth increases, we see an increase in Bill Length. b. Repeat the same scatterplot but now separate your plot into facets by species. How would you summarize the association between bill depth and bill length.

We can observe that the earlier observation still holds true, however for each species the rate of increase of bill length is

penguins_data<-palmerpenguins::penguins


ggplot(data=penguins_data,aes(y=bill_length_mm,x=bill_depth_mm,color=species))+
  geom_point()+
  geom_smooth(method='lm',se=TRUE)+
  facet_grid(species~.)+
  labs(y='Bill Length (in mm)',x='Bill Depth(in mm)',title='Comparing Bill Depth against Bill Length for Different Specices of Penguin',subtitle='Increasing Bill Depth results in increasing Bill Length although this rate is different across species')