R Markdown Presentations
A new slide is a level 2 heading “##”.
To do a slide without a title, start with ’***’.
When running R code, you can set comment = ""
to set the comment character or remove it completely:
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
Leaflet
Allows for the creation of interactive maps.
The mapping data is from OpenStreeMap.
We can add a marker:
You can add HTML into the popups, e.g. anchors/links.
To add many markers, you can create a data frame:
tibble(
lat = -c(36, 37, 38),
lng = c(143, 144, 145)
) %>%
leaflet() %>%
addTiles() %>%
addMarkers()
Custom Markers
ccc_icon <- makeIcon(
iconUrl = 'https://scontent.fmel7-1.fna.fbcdn.net/v/t31.0-1/cp0/c7.0.56.56a/p56x56/12045418_1173078239386251_5340026945367359072_o.jpg?_nc_cat=106&_nc_sid=dbb9e7&_nc_ohc=CVP7qbMvVsoAX_B5sru&_nc_ht=scontent.fmel7-1.fna&oh=e8ba7d82868ac3198b6a2771a32ecc39&oe=5EA97D59'
)
leaflet() %>%
addTiles() %>%
addMarkers(lat = -37.7298, lng = 144.9553, popup = 'Coburg Velodrome', icon = ccc_icon)
Mapping Clusters
tibble(
lat = runif(500, min = -37.8, max = -37.7),
lng = runif(500, min = 144.8, max = 145)
) %>%
leaflet() %>%
addTiles() %>%
addMarkers(clusterOptions = markerClusterOptions())
You can add circle markers:
tibble(
lat = runif(500, min = -37.8, max = -37.7),
lng = runif(500, min = 144.8, max = 145)
) %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers()
Can use a variable in the data frame to determine the radius.
Legend
Can add a legend with addLegend()
.