mages / googleVis

Interface between R and the Google Chart Tools
https://mages.github.io/googleVis/
360 stars 155 forks source link

BubbleChart with Fruits data, including a gradient color scale #81

Closed martinschmelzer closed 5 years ago

martinschmelzer commented 5 years ago

Using the following code

library(googleVis)
Bubble <- gvisBubbleChart(Fruits, idvar="Fruit", 
                          xvar="Sales", yvar="Expenses",
                          colorvar="Profit", 
                          options=list(
                            colorAxis="{colors: ['yellow', 'red']}",
                            hAxis='{minValue:75, maxValue:125}'))
plot(Bubble)

I intend to create a chart where the Profit column of the Fruits data is mapped to a gradient color scale from yellow to red. But the result does not show the gradient color scale. Somehow, in the JS output, the Profit column is of type string (in contrast to the R dataframe column) which prevents the gradient scale to be applied:

function gvisDataBubbleChartIDf63b69c63e04 () {
var data = new google.visualization.DataTable();
var datajson = [
                ["Apples", 98, 78, "20"],
                ["Oranges", 96, 81, "15"],
                ["Bananas", 85, 76, "9"]
               ];

/* ... SKIPPED SOME ROWS ... */
data.addColumn('string',' Profit');
data.addRows(datajson);
return(data);
}

Not sure if this is a bug?

mages commented 5 years ago

Yes, you are correct. Only character value were allowed for colorvar. I have updated this now to allow for either character or numeric values. Your example produces a gradient colour scale with the developer version of googleVis on GitHub.

martinschmelzer commented 5 years ago

Great! Thanks for solving this that quick!