我正在计划一艘帆船的航向。当我在控制台中运行以下代码时,它可以正常工作,并且在查看器中可以看到一张漂亮的地图。当我尝试在markdown中编织相同的地图时,总是会出现错误。
当我不对数据进行子集化并根据初始数据帧对地图进行绘制时,它可以很好地工作,由于某种原因,当绘制地图和绘制路线基于子集时,它不会编织。
lg = logdata
library(lubridate)
library(chron)
timex <- times(lg$Time)
lg$Time = as.POSIXct(lg$Time, format = "%H:%M:%OS")
logdate = lg$Date
datex = as.Date(logdate, format = "%d/%m/%Y")
tnd = as.POSIXct(paste(datex, timex), formate = "%d/%m/%Y %H:%M:%S")
lgT = cbind(lg, tnd)
# Defining race 1 timings (creating subset)-------------
library(svDialogs)
raceonestart = dlgInput("Race 1 start time eg: YYYY-MM-DD HH:MM:SS ", Sys.info()["raceonestart"])$res
raceoneend = dlgInput("Race 1 finish time eg: YYYY-MM-DD HH:MM:SS ", Sys.info()["raceonestart"])$res
r1 = subset(lgT, lgT$tnd > raceonestart & lgT$tnd < raceoneend)
# Creating the map----------
library(plotKML)
library(ggplot2)
library(ggmap)
library(gganimate)
register_google("key")
Lon = mean(r1$Lon)
Lat = mean(r1$Lat)
mapImageData <- get_googlemap(
center = c(lon = Lon, lat = Lat),
maptype = c("terrain")
)
race1map = ggmap(mapImageData, extent = "device") +
geom_line(
data = raceone,
mapping = aes(
x = r1$Lon,
y = r1$Lat,
color = raceone$SOG
),
size = 1
)
animate(race1map)
这是我看到的错误-
Quitting from lines 19-135 (gif_test.Rmd)
Error in if (lon < -180 || lon > 180) stop("longitude of center must be between -180 and 180 degrees. note ggmap uses lon/lat, not lat/lon.", :
missing value where TRUE/FALSE needed
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> get_googlemap
In addition: Warning messages:
这里是数据样本
> df <- dput(lg[1:20, c(1,2,3,4,27)])
structure(list(Date = c("19/10/2018", "19/10/2018", "19/10/2018",
"19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018",
"19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018",
"19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018", "19/10/2018",
"19/10/2018", "19/10/2018"), Time = structure(c(1550318776, 1550318777,
1550318778, 1550318779, 1550318780, 1550318781, 1550318782, 1550318783,
1550318784, 1550318785, 1550318786, 1550318787, 1550318788, 1550318789,
1550318790, 1550318791, 1550318792, 1550318793, 1550318794, 1550318795
), class = c("POSIXct", "POSIXt"), tzone = ""), Lat = c(35.8952,
35.8952, 35.8952, 35.8952, 35.8952, 35.8952, 35.8952, 35.8952,
35.8952, 35.8952, 35.8952, 35.8952, 35.8952, 35.8953, 35.8953,
35.8952, 35.8953, 35.8953, 35.8953, 35.8952), Lon = c(14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5,
14.5, 14.5, 14.5, 14.5, 14.5, 14.5, 14.5), SOG = c(0.058, 0.175,
0.039, 0.097, 0.078, 0.214, 0.233, 0.097, 0.097, 0.175, 0.078,
0.078, 0.039, 0.194, 0.116, 0.039, 0.117, 0.058, 0.019, 0.097
)), row.names = c(NA, 20L), class = "data.frame")