简体   繁体   English

使用ggmap和ggplotly

[英]using ggmap and ggplotly

I am trying to use ggmap with ggplotly, and I am having trouble making the packages work together. 我正在尝试将ggmap与ggplotly一起使用,并且我无法使这些包一起工作。 A search for the error message got me here . 搜索错误消息让我在这里 However, I am not sure how the aes inheritance is/could be a problem. 但是,我不确定aes继承是如何/可能是一个问题。 The strange thing is that 'myPlot' created with ggmap works just fine in RStudio, but cannot connect to ggplotly. 奇怪的是,使用ggmap创建的'myPlot'在RStudio中运行得很好,但无法连接到ggplotly。 The map data is from here . 地图数据来自这里

Is it possible to get these two packages working together? 是否有可能让这两个包一起工作? (By the way, I cannot tag this as ggplotly, I dont think that package has been referenced on SO before.) (顺便说一句,我不能将其标记为ggplotly,我不认为之前已经在SO上引用过该包。)

Code

lapply(list("ggplot2", "ggmap", "mapproj", "RCurl", "RJSONIO", "plyr"), 
       require, character.only=TRUE)
# install.packages("devtools")
library("devtools")
# install_github("plotly", "ropensci")
library(plotly)

mapImageData1 <- get_map(location = c(lon = -0.016179, lat = 51.538525),
                         color = "color",
                         source = "google",
                         maptype = "satellite",
                         zoom = 17)

myMap = ggmap(mapImageData1,
      extent = "device",
      ylab = "Latitude",
      xlab = "Longitude")

py <- plotly("RgraphingAPI", "ektgzomjbx")
res <- py$ggplotly(gg = p_map)

Error Message 错误信息

res <- py$ggplotly(gg = p_map) Error in eval(expr, envir, enclos) : object 'lon' not found res < - py $ ggplotly(gg = p_map)eval(expr,envir,enclos)中的错误:找不到对象'lon'

just replace within your existing dataframe the column names for latitude and longitude like this at the start 只需在现有数据框中替换纬度和经度的列名,就像在开始时一样

(if p_map is your dataframe) (如果p_map是你的数据帧)

setnames(p_map, "Latitude", "lat")
setnames(p_map, "Longitude", "lon")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM