R googleVis BubbleChart, set size without setting colours
Asked Answered
L

1

6

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)
Lewendal answered 15/12, 2015 at 12:9 Comment(3)
Just to clarify the reason why sizevar is identified as colorvar, taken from the command's help file: "A bubble chart is used to visualize a data set with 2 to 4 dimensions. The first two dimensions are visualized as coordinates, the 3rd as color and the 4th as size." Based on that statement I don't think there is an easy way plot only three variables without changing the tool tip manually.Hankhanke
Thanks for the tip I did not reach that sentence in the helpfile. I looked at google charts' documentation and it seems that the issue is inherited from the original design. I will try to customise the tooltip myself, but I don't know if I will achieve to be as flexible as I'd like.Lewendal
Yeah, I've tinkered myself with editing the tool tip manually, using gsub() etc, but it wasn't straight forward and I gave up after a half hour. I don't think it'll be very flexible in the end.You might want to submit a bug / file an issue with the developers for this one...Hankhanke
G
4

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")
Greatnephew answered 15/12, 2015 at 12:55 Comment(3)
The problem suffers from the same issue my second approach does, it has two values in the tooltip: Weight and Weight.1.Lewendal
You can add the labels manually : with(bubbledata, text(Y~X, labels = Weight, pos = 4))Greatnephew
In the worst case scenario, I believe the tooltip can be customised. However, I was hoping there was a simpler way to plot the BubbleChart with three variables. The BubbleChart can be plot with 2 or 3 variables i.e. bubble <- gvisBubbleChart(bubbledata, idvar="id",xvar="X", yvar="Y"); so it isn't true that 4 variables are mandatory (4+1(id) in reality). For some reason, the sizevar is identified as colorvar, hence my question.Lewendal

© 2022 - 2024 — McMap. All rights reserved.