Reputation: 157
I made a bubble chart similar to the example code below (not a car guy, sorry if it doesn't make sense). In my case, I have a unique ID to each row of data that I would like shown in the tooltip of each bubble, along with the other data defined in the axis and size.
This example code I have made does not seem to show anything when I try to specify the car name of each bubble in the tooltip. But, when I replace the sprintf() argument for a simple string, it shows on all of the bubbles but not the other data described above.
Suggestions on doing this better or is there an answer to my problem?
library(highcharter)
df = data.frame(Car = row.names(mtcars), mtcars, row.names = NULL)
hchart(df, "bubble", hcaes(x = drat, y = wt, group = gear, size = mpg),
tooltip = list(pointFormat = sprintf("Car: %s", df$Car)))
Upvotes: 0
Views: 379
Reputation: 884
I think you would be able to do this using the tooltip.formatter from the highcharts js API: https://api.highcharts.com/highcharts/tooltip.formatter
You can see a handy article on how to do it here: https://www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR3UzztbrY4rdCbOw1W7DmSq4mWJswJZxIw-xOqGbjIRExj-gsuVEO2zM00
library('highcharter')
highchart() %>%
hc_add_series(
type = "bubble",
data = list(5, 4, 3, 5)
) %>%
hc_chart(events = list(load = JS("function() {
var chart = this; chart.update({
tooltip: {
formatter: function () {
return 'The value for <b>' + this.x +
'</b> is <b>' + this.y + '</b>';
}
}
});
}
")
))
Upvotes: 1