July 29, 2019
Instructor: Andy Hong, PhD
Lead Urban Health Scientist
The George Institute for Global Health
University of Oxford
# Initialize a plot
ggplot(data, aes(x = x, y = y))
# Histogram
ggplot(data, aes(x = x, y = y) + geom_histogram()
# Scatter plot
ggplot(data, aes(x = x, y = y) + geom_point()
# Adding a trend line
ggplot(data, aes(x = x, y = y) + geom_point() + geom_smooth()
# Box plot
ggplot(data, aes(x = x, y = y) + geom_boxplot()
# Initialize a map
leaflet(data) %>% addTiles()
# Add markers
leaflet(data) %>% addTiles() %>%
addCircleMarkers(~long, ~lat)
# Visualize data
leaflet(data) %>% addTiles() %>%
addCircleMarkers(~long, ~lat, radius=~value)
# Add colors
leaflet(data) %>% addTiles() %>%
addCircleMarkers(~long, ~lat, color=~value)
# Add labels
leaflet(data) %>% addTiles() %>%
addCircleMarkers(~long, ~lat, label=~label)