gpt4 book ai didi

r - 使用 ggmap 和 ggplotly

转载 作者:行者123 更新时间:2023-12-04 09:50:13 28 4
gpt4 key购买 nike

我正在尝试将 ggmap 与 ggplotly 结合使用,但我无法让这些包协同工作。搜索错误消息得到了我 here .但是,我不确定 aes 继承是/可能是一个问题。奇怪的是,用 ggmap 创建的“myPlot”在 RStudio 中工作得很好,但无法连接到 ggplotly。 map 数据来自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 <- py$ggplotly(gg = p_map) Error in eval(expr, envir, enclos) : object 'lon' not found

最佳答案

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

(如果 p_map 是您的数据框)

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

关于r - 使用 ggmap 和 ggplotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23373908/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com