R googleVis: How can I gvisGeoMap multiple variables using markers

613 views Asked by At

I have a dataframe in which some states are characterized by two variables. Briefly you can think of every row as a vector of (state,var1,var2). I want to map states using googleVis package. My approach is to use markers whose size and color represent var1 and var2 respectively. I can be able to only represent one variable using the following code:

require(googleVis)
map <- gvisGeoMap(df_by_state, locationvar = 'state', 
                  numvar = 'var1',
                  options = list(dataMode = 'markers',
                                 region = 'US'))
plot(map)

The above code generates a map with markers. enter image description here

However the size and color of the marker both represent the SAME variable, var1. How can I proceed to represent var2 in the color of the markers while var1 is encoded in the size?

1

There are 1 answers

0
kthouz On BEST ANSWER

I was able to do it using gvisGeoChart instead

map <- gvisGeoChart(df, locationvar = 'state',
                    colorvar = 'var1', sizevar = 'var2',
                    options = list(region = 'US',displayMode = 'markers'))
plot(map)

enter image description here

However, if you still know how to do it with gvisGeoMap, I will appreciate that.

Thank you