st_normalize.sfc(x,c(x_range [1],y_range [1],x_range [2],y_range [2])中的错误:域必须具有正数范围

问题描述 投票:0回答:1

背景:

我正在使用ggplot2 geom_point按周映射动物位置点。作为底图,我正在使用计算机中的shapefile。

这是我的数据的示例:

datexample <- data.frame(
  "animal" = c("A","B"), 
  "yearweek" = c(202028, 202028, 202029, 202029),
  "lat" =  c(45.25, 44.75, 45.25, 45.75), 
  "lon" = c(-61.75, -61.25, -62.75, -62.25)
)
datexample

这里是不添加底图的ggplot的示例:

geom_point(data = dat, aes(x = lon, y = lat, alpha = yearweek))+
  facet_grid(cols = vars(animal)) +
  xlab("Longitude")+
  ylab("Latitude")

问题:

上面的代码在我将R和RStudio更新到最新版本(上周)之前有效。现在,这些地图将不会绘制,并且出现以下错误:

Error in st_normalize.sfc(x, c(x_range[1], y_range[1], x_range[2], y_range[2])) : domain must have a positive range 

我尝试过的事情:

  • 重新启动R和RStudio
  • 重新安装并更新了ggplot2和dplyr

我尚未将shapefile移动到计算机上的另一个文件夹,并且它们已正确导入RStudio。我还正确定义了[[coord_sf。就像我说的那样,此代码在更新之前一直有效。任何帮助,将不胜感激。

r ggplot2 rstudio shapefile geom
1个回答
0
投票
我对您的代码进行了一些小的修改,并且能够使用下面显示的r版本(R版本3.6.3。这是您期望看到的内容吗?

ggplot(data = datexample) + geom_point(aes(x = lon, y = lat, alpha = yearweek)) + facet_grid(cols = vars(animal)) + xlab("Longitude")+ ylab("Latitude")

[![在此处输入图片描述] [1]] [1]

> sessionInfo() R version 3.6.3 (2020-02-29) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows Server x64 (build 14393) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggspatial_1.1.2 forcats_0.5.0 stringr_1.4.0 dplyr_0.8.5 purrr_0.3.3 readr_1.3.1 [7] tidyr_1.0.2 tibble_3.0.0 ggplot2_3.3.0 tidyverse_1.3.0 [1]: https://i.stack.imgur.com/9gAF6.jpg

© www.soinside.com 2019 - 2024. All rights reserved.