Haojia Li 4/18/23
This project adopts the practice in Part 3, Lab 3. We are going to use the met data and the station data to locate the most representative USAF station at either country level or state level by identifying the station with the smallest euclidean distance.
Leaflet is one of the most popular open-source
JavaScript libraries for interactive maps. The
leaflet
package makes it easy to
integrate and control Leaflet maps in R.
I will introduce the following features of leaflet as I show my results of the visualization:
-
data object - Both
leaflet()
and the map layer functions have an optional data parameter that is designed to receive spatial data in one of several forms. We will only focus on data frame with lng/lat columns from base R; -
basemaps - Default tiles by
addTiles()
and third-party tiles byaddProviderTiles()
and callingproviders
; -
map methods -
setView()
;fitBounds()
will be used in the Shiny app; -
add elements
-
Use
addMarkers
to add markers to the map for the 5 most representative stations in the United States in terms of wind speed, temperature, dew point, atmosphere pressure, and relative humidity; -
Use the
popup
argument to add pop up the relevant information upon click, such as:USAFID: 724016
Name: CHARLOTTESVILLE ALBEMARLE ARPT
Number of records: 1027
Wind speed: 1.5 km/h
Temperature: 23.3โ
Dew point: 18.9โ
Atmospheric pressure: 1014.9 hPa
Relative humidity: 76.6%
Distance score: 1.3 -
Use
addCircles
add circles to the map for the top 10 or top 10% representative stations in each state in terms of all the weather conditions, using circle size to visualize the number of records and color to visualize the euclidean distance, and useaddLegend
to add color legend for the distance score; -
Use the
group
argument andaddLayersControl
to add layers to the map for each weather conditions, so that the user can access not only the representative stations of all weather conditions but also those being representative in regards to a single condition within only one leaflet output.
If time permits, I will also add how to add plots as popup and how to save leaflet as image to this part.
Thinking about the following problems:
-
The static leaflet is interactive, however limited. The developer need to have all the results computed locally.
-
We only included 6 layers in the static leaflet. However, given that there are 5 weather conditions, theoretically we can have up to
$2^5-1$ combinations of potential interest. -
The user might want to adjust the number of representative to be identified.
-
We visualized global weather condition of each station, state and the United States in August, but we might interested in how the weather, then the representative station(s), changed in the 31 days of the month. We might also interested in the weather during a certain period of the day, for example in the morning from 8 am to 12 pm.
All above are the motivations for a Shiny app, which makes it easy to build interactive web apps straight from R.
I am going to start with a brief introduction of the structure of a Shiny app - ui and server. I will also add some useful links, such as Shiny Gallery, Shiny Learning Resources and shinyWidgets, for reference.
To add flexibility and dynamic to the analysis, my Shiny app with include:
-
checkboxGroupButtons
for the weather conditions; -
numericInput
s for number and percentage of representative, at country level or state level; -
sliderInput
for hours from 0 to 23, so that the user can specify the time interval of interest; -
sliderInput
for day, with animation control.
If time permits, I will add a new tab panel to include plotly
and
DT::datatable
.