chamaoskurumi
chamaoskurumi

Reputation: 2493

How can I get proportional bubble sizes from R bubbleGoogleMaps?

I would like to use bubbleGoogleMaps to create a map of spatialpoints with bubbles sized proportionally to their individual value. Anyways, that is whatbubbleGoogleMaps is promising according to the documentation.

However, I realized that the bubble sizes are not propotional to their individual values, but only to their bin they fall into.

By default bubbleGoogleMaps only uses 5 bins based on the quantiles, which easily results in very misleading maps, as the following example will demonstrate:

library("plotGoogleMaps")

data(meuse)
coordinates(meuse)<-~x+y 
proj4string(meuse) <- CRS('+init=epsg:28992')

# we want to see one gigantic bubble for the first observation
# --> let's augment its value to 10000:
meuse$zinc[1] <- 10000 

# However, there is no gigantic bubble in the following bubbleGoogleMaps! 
# --> Bubbles are NOT proportional to their individual values!!!
m <- bubbleGoogleMaps(meuse,
                      zcol='zinc',
                      max.radius = 100,
                      filename='myMap.htm')

So I tried to create a workaround by augmenting the number of bins (=option 'key.entries') from 5 to 20:

keys <- signif(quantile(meuse$zinc,
                        probs = seq(0, 1, length.out=20),
                        na.rm=T,
                        names=F),3);keys

However, this workaround does not work, we get an error here:

m <- bubbleGoogleMaps(meuse,
                      zcol='zinc',
                      max.radius = 100,
                      key.entries=keys, 
                      filename='myMap.htm')

Any ideas how to create a bubbleGoogleMap with (individually) proportional bubbles?

Or does anyone know how to make the workaround with the option key.entries work?

Upvotes: 2

Views: 607

Answers (1)

chamaoskurumi
chamaoskurumi

Reputation: 2493

The author of the plotGoogleMaps package solved my problem. He confirmed that bubbleGoogleMaps works with bins indeed.

For augmenting the number of bins to 20 we need to set key.entries to

key.entries= quantile(meuse@data[, 'zinc'], (1:20)/20)

or for unique values

key.entries= unique(sort(meuse$zinc))

This is what I originally wanted. However, the legend is now getting very messy/massive or even not functioning anymore...

Upvotes: 2

Related Questions