Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R googleVis BubbleChart, set size without setting colours

Tags:

r

googlevis

I am trying to make a bubble chart with two coordinates and a size parameter with gooogleVis in R.

When I don't establish the colour variable, the size variable is used as colour instead of as size. I can include a colorvar but then the variable is displayed in the tooltip.

How can I avoid this behaviour?

I include a minimum working example with the two cases mentioned before:

library(googleVis)
set.seed(1)

bubbledata<-data.frame(id=rep("",100),X=sample(10,10,rep=TRUE),
                       Y=sample(10,10,rep=TRUE),Weight=sample(10,10,rep=TRUE))

# This graph uses sizevar as colorvar
bubble <- gvisBubbleChart(bubbledata, idvar="id",
                           xvar="X", yvar="Y",colorvar="",
                           sizevar="Weight")
plot(bubble)

bubbledata$colour<-""

# The output of this one is ok but the tooltip includes the colour var
bubble2 <- gvisBubbleChart(bubbledata, idvar="id",
                          xvar="X", yvar="Y",colorvar="colour",
                          sizevar="Weight")
plot(bubble2)
like image 626
Jon Nagra Avatar asked Dec 15 '15 12:12

Jon Nagra


1 Answers

If you only want one extra dimension to your bubblechart, then I think it is sensible to assign 'weight' to both sizevar and colorvar, like this:

bubble <- gvisBubbleChart(bubbledata, idvar="id",
                      xvar="X", yvar="Y",
                      sizevar="Weight", colorvar = "Weight")
like image 130
mtoto Avatar answered Sep 30 '22 13:09

mtoto