Geospatial
Continuous Outcome
{ggmap} Dot map
Example: Does Price vary by location?
In your data, find the min and max latitude and longitude to specify a bounding box
library(ggmap) <- c(left = min_longitude, bbox bottom = min_latitude, right = max_longitude, top = max_latitude) <- get_stamenmap(bbox, zoom = 13) map_tiles
(Optional) Aggregate some of the data (i.e. dots)
<- dat %>% agg_dat group_by(latitude = round(latitude, 2), longitude = round(longitude, 2)) %>% summarize(avg_outcome = mean(numeric_outcome), n = n())
scale_size_continuous
adjusts the range of dot sizes. This range makes them a little smaller.
ggmap(map_tiles) + geom_point(aes(longitude, latitude, size = n, color = avg_outcome), data = agg_dat) + scale_color_gradient2(low = "blue", high = "red", midpoint = midpoint_value_of_numeric_outcome, trans = "log10", labels = dollar) + scale_size_continuous(range = c(0.5, 4)) + theme_map() + labs(color = "avg_outcome", size = "n")
- trans and labels are for the legend (I think).