I'm able to make a great hPlot using the following code:
我可以使用以下代码创建一个很棒的hPlot:
h1<-hPlot(x = "MedianAge",
y = "AnnualPopulationGrowth",
data = df,
type = "bubble",
size="AdolescentFertilityRate", group = "continent")
h1$title(text='Median Age vs Annual Population Growth in 2010')
h1
However, I have a field in my data.frame df, called "Name", that I want to display. I tried adding the following line:
但是,我在data.frame df中有一个字段,名为“Name”,我想显示它。我尝试添加以下行:
h1<-hPlot(x = "MedianAge",
y = "AnnualPopulationGrowth",
data = df,
type = "bubble",
size="AdolescentFertilityRate", group = "continent")
h1$title(text='Median Age vs Annual Population Growth in 2010')
h1
However that doesn't work. Variations on this line like:
然而,这不起作用。这条线的变化如:
h1$tooltip(formatter("#! function(d) {return d.Name} !#"))
also do not work. Any help getting the name of the country to pop up in the tooltip would be awesome, thanks.
也不行。任何有助于在工具提示中弹出国家名称的帮助都会很棒,谢谢。
1 个解决方案
#1
1
Here is a minimal example:
这是一个最小的例子:
library(rCharts)
# data
df <- data.frame(x = 1:10, y = rnorm(10), s = rnorm(10), z = letters[1:10])
# create plot object
p <- hPlot(y ~ x, data = df, size = "s", type = "bubble")
# fix data format
p$params$series[[1]]$data <- toJSONArray(df, json = F)
# add tooltip formatter
p$tooltip(formatter = "#! function() {return(this.point.z);} !#")
# show
p
#1
1
Here is a minimal example:
这是一个最小的例子:
library(rCharts)
# data
df <- data.frame(x = 1:10, y = rnorm(10), s = rnorm(10), z = letters[1:10])
# create plot object
p <- hPlot(y ~ x, data = df, size = "s", type = "bubble")
# fix data format
p$params$series[[1]]$data <- toJSONArray(df, json = F)
# add tooltip formatter
p$tooltip(formatter = "#! function() {return(this.point.z);} !#")
# show
p