Reputation: 529
Is there a way to change the marker size in a map based on a certain value?
For example, if I were plotting the population of individual cities and the marker was a circle, the circle would be bigger for the more populated cities.
I was wondering if there was a specific feature for this or if I could add a column to the dataset which has the individual marker sizes for each lat/lon I want to plot.
Thanks!
Upvotes: 11
Views: 14594
Reputation: 154
You can also use the rescale
function if dividing the values does not work well:
leaflet(df) %>% addTiles() %>%
addCircleMarkers(
radius = ~ rescale(quantity, c(1,10)),
stroke = FALSE, fillOpacity = 0.5
)
Upvotes: 2
Reputation:
Let's say you have a field in your spatial points data frame (df) called quantity, and you want to make the radius of the marker the size of the square root of the quantity. Then the command would be:
leaflet(df) %>% addTiles() %>%
addCircleMarkers(
radius = ~ sqrt(quantity),
stroke = FALSE, fillOpacity = 0.5
)
Upvotes: 14