When I saw that Posit had posted a blog post about storytelling with Quarto (see blog post here) using Closeread I became interested in trying out Closeread for this competition. This is my first time reading about Closeread and it sparked my interest in trying to tell a story using a quarto document. For my submission, I thought I would do something silly about a topic that is serious. I wanted to show the weather differences in Los Angeles from 2003 to 2023 by creating a story of global warming while showing visualizations of the temperature differences using “temperature blankets”. If you know anything about me, the first thing you recognize is art != JP so instead I thought I would create a temperature blanket using ggplot2.
For the competition I decided to do everything in R because I knew I was going to be mess around a lot using the theme() function in ggplot2. Below is going to be a walkthough of my thought process for creating the Closeread story. Then I will probably create a Closeread specific folder within a GitHub repo or its own repo.
Retrieving the Data
I originally was going to use this site to create the year of data for my location. However, I found that the website uses an API that has an R package and a Python package. Shout out for those that made the API and the packages. This post will follow the R package.
I will be using the weather_history() function, but there are some other interesting functions for forecasting in that package as well. From the documentation, the location can either be a latitutde x longitude vector or a string of a place. Figuring that LA is well known I used that for the location and then included the dates for the year of data I am interested in. The dates must follow the format of YYYY-MM-DD and when I ran the function orignally, I realized my temperatures were in Celsius. I decided to simply add a calculation to change it to Fahrenheit. To do the calculation, I used the formula below. Since all the data matched up, I decided to bind the two dataframes and check to make sure it was correct by viewing the first and last 5 rows.
Okay, everything looks okay to me. I am going to focus on the average temperature to create my temperature blankets. I also just want to point out that all temperatures will be in Farenheit. Before making my visualization, I want to break down my date category into years, months, and days. This will be easier to use facet_wrap() to separate my years.
Now, we can focus on creating our plot. Interestingly, I have never had to make one axis on my plots be set to an amount that would range across the entirety of the axis. This was definitely one of those times where I just tried something and BAM! it worked. I set my y-axis to 1 and it worked. We will not focus on the values for the y-axis because they don’t make any sense, but I did try some other values. The value that you choose on the y-axis does not matter, especially for this visualization because we are going to remove the axis titles and text.
We need a color scale. This will be a manual scale to try and make a cool blanket style so after some googling I found this scale project sheet. This was the easiest scale to follow (for me) and the large balls of yarn allowed me to find color codes that matched the yarn fairly well.
Some quick coding of the temperature ranges and the months should set up the template for my blanket design.
I was thinking about how to show the progress of the blanket. I decided to use the dplyr::first() function, which was a first for me. Here I have the first day of the year with the temperature range values for 2003 and 2023.
Next, I decided to do a quick loop where I used two different seq() functions. The first sequence was to creatte a row for each day of the year from 1 to 365 by each day. I was able to create rows called year_row for both years. There is probably a better way of doing this but I decided on using a filter() where I looped through each day and put that each day was less than the year_row column created. For instance, in the code chunk below you can see it as filter(year_row < .x). So when the loop starts at 2 it will filter for values that are lower than 2, with the only value being 1. This will be important later on because I am not sure if I want to present a story of the weather and a creation of my blanket for every single day or if there is another metric to go by.
I ended up deciding on showing my blanket every week. I’m still not sure about it since there are are 52 plots to look through. Also, now that I think about it, maybe LA was not the best place to showcase temperature for a blanket. Looking at the final blanket plot, it screams “Sorry its always nice here!” and that might not be the most interesting for a temperature blanket. I’ll have to start looking at other locations for better blanket designs. At least now I have the basic design of what I’ll do for the competition.