Assignment 3

Author

Your Name

Published

March 10, 2024

Instructions

Please submit your assignment as html file to me via email. Please call your assignment: “yourname_assignment3.html”. For example, I would submit submit something called “popescu_assignment3.html”. Please make sure that it is all in lower case. Please answer all the questions below.

Notice that some questions have more points than others. The maximum points on this assignment is 29.

1 Question

Total points: 1

Download the provided dataset containing air quality measurements from various monitoring stations in major cities in the US. Load in R using the `read.csv’ function. The original data is from the US Environmental Protection Agency.

2 Question

Total points: 1

The average small particulate matter (PM2.5) concentration has been used as an indicator for fine-particle air pollution. This has been of particular concern to regulators and public health experts because its microscopic size means it can be inhaled and absorbed into the bloodstream. Create a new dataframe by selecting “PM2.5 - Local Conditions” for parameter name and “PM25 24-hour 2012” for pollutant standard.

3 Question

Total points: 1

What are the dimensions of the final dataframe? How many columns and how many rows are there?

4 Question

Total points: 4

Now create the following map (as close as possible to what you see below). To get full points you need to

  • Load the US shapefile from relevant sources (1 point)
  • Decide on map coordinate extent (1 point)
  • Have a legend that contains both colors and sizes (1 point)
  • The variable that needs to be plotted has to be Arithmetic.Mean (1 point)
Loading required package: viridisLite

5 Question

Total points: 1

Create a histogram for the Arithmetic.Mean. Please use 30 for the number of bins. Also ensure that the density function is plotted alongside the histogram as displayed below:

6 Question

Total points: 3

Since 1880, average global temperatures have increased by about 1 degrees Celsius (1.7° degrees Fahrenheit). Global temperature is projected to warm by about 1.5 degrees Celsius (2.7° degrees Fahrenheit) by 2050. Understanding how temperature evolved over time is important.

Download the country-level global data with annual temperatures since 1901.

You can also download the world shapefile.

Produce a map for 1901 focusing on Europe using the following extent:

min_lon_x<-(-31.28296)
max_lon_x<-(40.12832)
min_lat_y<-34.93447
max_lat_y<-80.47783

The countries that you should keep to simplify the shapefile are:

list_ctries<-c("Albania",
"Andorra",
"Austria",
"Belarus",
"Belgium",
"Bosnia and Herzegovina",
"Bulgaria",
"Croatia",
"Czech Republic",
"Denmark",
"Estonia",
"Finland",
"France",
"Germany",
"Greece",
"Hungary",
"Ireland",
"Italy",
"Kosovo",
"Latvia",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macedonia",
"Malta",
"Moldova",
"Monaco",
"Montenegro",
"Netherlands",
"Norway",
"Poland",
"Portugal",
"Republic of Serbia",
"Romania",
"Russia",
"San Marino",
"Slovakia",
"Slovenia",
"Spain",
"Sweden",
"Switzerland",
"Turkey",
"Ukraine",
"United Kingdom",
"Vatican")

In this specific case, when you merge the dataframe to the shapefile, you should not use a left_join. This is because many countries have more than one polygons. Because the two shapefiles are already in alphabetical order, we can use cbind. This will put the two columns together. The other relevant function here is rbind, which binds rows. You can read more about the difference between cbind and rbind.

To get full points:

  • use the viridis theme to represent temperature (1 point)
  • edit the legend title appropriately (1 point)
  • add the country temperature inside the polygons using the geom_sf_text function (1 point)

Your map should look like below:

7 Question

Total points: 1

Create a histogram based on the temperature data for 1901. It should look like below. Choose 30 bins and add the appropriate density function.

8 Question

Total points: 5

Produce the following map for 1901. To get full points you need:

  • use the correct map coordinate extent (1 point)
  • use the viridis theme to represent temperature (1 point)
  • edit the legend title appropriately (1 point)
  • add the country temperature inside the polygons using the geom_sf_text function (1 point)
  • have the histograms on the right hand side (1 point)

9 Question

Total points: 5

Produce the following map for 2022 To get full points you need:

  • use the correct map coordinate extent (1 point)
  • use the viridis theme to represent temperature (1 point)
  • edit the legend title appropriately (1 point)
  • add the country temperature inside the polygons using the geom_sf_text function (1 point)
  • have the histograms on the right hand side (1 point)

10 Question

Total points: 3

Produce the following animation:

Hint: You need to turn your dataframe from wide to long before you can create an animation.

head(ctries_eu_joined[order(ctries_eu_joined$SOVEREIGNT), ], n = 10)
head(ctries_long[order(ctries_long$SOVEREIGNT), ], n = 10)

11 Question

Total points: 1

This is an interesting an aimation, but it is difficult to see exactly how temperature might have changed over time. Now plot a time trend of yearly temperature

12 Question

Total points: 3

The previous time trend was too volative and thus, difficult to see. Make a 5-year average using using the rollmean function from the zoo library.