我正在使用来自openair包的R< scatterPlot绘制轨迹(纬度与经度)。将轨迹与“'组”分组时。选项,最后一组没有绘制。 以下是示例代码:
df = data.frame(name = c(rep('C1',10),rep('C2',10),rep('C3',10),rep('C4',10)),
lat = seq(1,100,2.5),
lon = seq(101,200,2.5))
scatterPlot(df ,x = "lon", y = "lat", group = "name",map = TRUE )
scatterPlot(df ,x = "lon", y = "lat")
此外,我在尝试在后台绘制地图时出错:"使用数据包1时出错。长度为零的参数i"
由于 Ilik
答案 0 :(得分:3)
似乎是代码中的错误(基于lattice :: xyplot)。 openair::scatterPlot
的代码看起来很业余:
# ------segment where `group` parameter is passed to lattice code ---
id <- which(names(mydata) == group)
names(mydata)[id] <- "MyGroupVar"
plotType <- if (!Args$traj)
c("p", "g")
else "n"
if (method == "scatter") {
if (missing(k))
k <- NULL
Type <- type
xy.args <- list(x = myform, data = mydata, groups = mydata$MyGroupVar,
type = plotType, as.table = TRUE, scales = scales,
#---- end of extract
使用重命名分组变量然后将$与mydata$MyGroupVar
一起使用是一种破解。应该使用mydata[[group]]
更简单,更不容易出错。建议你要求修复错误。
如果您执行traceback()
,则可以看到生成数据包错误时传递的参数:
回溯() 4:xyplot.formula(x = lat~lon | default,data = list(lon = c(101, 103.5,106,108.5,111,113.5,116,118.5,121,123.5,126,128.5, 131,133.5,136,138.5,141,143.5,146,148.5,151,153.5,156, 158.5,161,163.5,166,168.5,171,173.5,176,178.5,181,183.5, 186,188.5,191,193.5,196,198.5),lat = c(1,3.5,6,8.5, 11,13.5,16,18.5,21,23.5,26,28.5,31,33.5,36,38.5,41, 43.5,46,48.5,51,53.5,56,58.5,61,63.5,66,68.5,71,73.5, 76,78.5,81,83.5,86,88.5,91,93.5,96,98.5),默认= c(1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L),MyGroupVar = c(1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L)),groups =“name”,type = c(“p”,“g”),as.table = TRUE,
(我认为)......“name”周围的引号可能会导致错误。它应该作为一个不带引号的真实R名称/符号传递。
我认为你可以非常接近你想要的普通格子:
xyplot(data=df , lon~lat, groups = name, auto.key=TRUE, grid=TRUE)
如果您需要调整此内容,请参阅?xyplot
。