interactive/reactive 经度和纬度点的带有 ggmap 的 R ggiraph - 比例或轴问题?

R ggiraph with ggmap for interactive/reactive longitude and latitude points - scale or axis issue?

新的 ggiraph 包非常适合让 ggplot2 响应用户的鼠标,没问题。

但是 我无法使用 ggmap() 为 interactive/reactive 经度和纬度点 .

正常工作

交互性很好,当鼠标悬停在一个点上时我可以得到工具提示响应,但是当与 ggmap() 一起使用时,比例或轴似乎有问题。

下面的代码块提供了我正在尝试解决的问题的可重现示例,并且还链接了一些图像来说明我的意思。

安装需要的包,然后补小示例数据集,然后下载需要的图 使用 get_map() 函数:

#Install required_packages:
required_packages <- c("ggmap", "ggplot2", "ggiraph")
new.packages <- required_packages[!(required_packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
#Load required_packages:
lapply(required_packages, require, character.only = TRUE)

#Make small example data set:
suburb<-c("BURNLEY","COLLINGWOOD","MALVERN","PRAHRAN","RICHMOND","SOUTH YARRA","ST KILDA","ST KILDA WEST","TOORAK","WINDSOR")
lon<-c(145.0176466,144.98815,145.036,144.998,144.998,144.989,144.982,144.9732,145.018,144.988)
lat<-c(-37.8299258, -37.8019,-37.857,-37.852,-37.823,-37.84,-37.864,-37.8604,-37.841,-37.854)
`Change 2005-2015 (%)`<-c(112, 120, 136, 127, 122, 115, 110, 146, 120, 128)
df<-data.frame(suburb, lon, lat, `Change 2005-2015 (%)`)

#Download map from google maps
SOUTH_YARRA <- get_map(location = 'South Yarra, Australia', zoom = 13, maptype="terrain")

现在我可以使用下面的代码创建静态地图了:

ggmap(SOUTH_YARRA) + 
    geom_point(data = df, 
               aes(x =lon, y= lat, size=`Change 2005-2015 (%)`, colour = `Change 2005-2015 (%)`),
               alpha=0.75) +  
    scale_colour_gradientn(colours=rainbow(5)) +
    scale_radius (range = c(6, 12), trans = "identity", guide = "legend") +
    ggtitle("Total change in Median \n House Price (%) from 2005-2015 \n")

here is the static map produced by the code above - no problem

但是,当我使用 ggiraph 的 geom_point_interactive() 使地图中的点对用户的鼠标悬停做出反应时,比例或轴出现问题:

#Try add reactivity using ggiraph's geom_point_interactive() instead of geom_point()
interactive_map<-ggmap(SOUTH_YARRA) + 
    geom_point_interactive(data = df, 
                           aes(x =lon, y= lat, size=`Change 2005-2015 (%)`, colour = `Change 2005-2015 (%)`, tooltip=suburb, data_id = suburb),
                           alpha=0.75) +  
    scale_colour_gradientn(colours=rainbow(5)) +
    scale_radius (range = c(6, 12), trans = "identity", guide = "legend") +
    ggtitle("Total change in Median Melbourne \n House Price (%) from 2005-2015 \n")

ggiraph(code = {print(interactive_map)}, zoom_max = 5,
        tooltip_offx = 20, tooltip_offy = -10, 
        hover_css = "fill:black;",
        tooltip_opacity = 0.7)

here is a still image of my scale/axis problem produced by the code above. Note the the code above makes the tooltip reactivity works fine for mouse hover, it's just this scale problem that I need to resolve

我试过将 maprange、extent 和 base_layer 参数更改为 ggmap() 函数,例如:

ggmap(SOUTH_YARRA, maprange=TRUE, extent = "panel", base_layer = ggplot(data = df, aes(x =lon, y= lat)))

然而这并没有帮助。 ggiraph 是一个很棒的包恕我直言,因为它是新的,所以在 Whosebug 等方面还没有太多关于它的信息。任何帮助将不胜感激!

这是 ggiraph 包中的错误,包维护者刚刚修复了它,请参阅此处的 github 错误报告了解更多详细信息:https://github.com/davidgohel/ggiraph/issues/32#issuecomment-257869888