【问题标题】:using ggmap and ggplotly使用 ggmap 和 ggplotly
【发布时间】:2014-06-15 22:28:59
【问题描述】:

我正在尝试将 ggmap 与 ggplotly 一起使用,但无法使这些包一起工作。搜索错误消息让我得到here。但是,我不确定 aes 继承是/可能是一个问题。奇怪的是,使用 ggmap 创建的“myPlot”在 RStudio 中工作得很好,但无法连接到 ggplotly。地图数据来自here

这两个包可以一起工作吗? (顺便说一句,我不能把它标记为 ggplotly,我不认为这个包之前在 SO 上被引用过。)

代码

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)

错误信息

res

【问题讨论】:

    标签: r ggplot2 plotly ggmap


    【解决方案1】:

    只需在现有数据框中替换一开始的纬度和经度的列名

    (如果 p_map 是您的数据框)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-16
      • 2018-11-08
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 2021-06-06
      • 2023-04-05
      相关资源
      最近更新 更多