r - st_normalize.sfc(x, c(x_range[1], y_range[1], x_range[2], y_range[2])) 中的错误:域必须具有正范围
问题描述
背景:
我正在使用 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 版本(R 版本 3.6.3)获得此图。这是你期待看到的吗?
library(tidyverse)
library(ggspatial)
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/gfwce.jpg
推荐阅读
- python-3.x - boto3 python SetupAWS.py 设置“aws 配置”
- phpstorm - PhpStorm Ubuntu 18.041 浏览器无法启动
- android - 如果 SQLite 为空或有记录,则更改片段中的视图
- c++ - 如何实现我的自定义范围 for 循环?
- php - Symfony 3.4 使用后不删除令牌
- python-2.7 - _init_cffi_1_0_external_module 上的 Python Cryptography 运行时错误
- ruby - 向 ruby 中的 api 发送 HTTP 发布请求
- google-chrome - Web 蓝牙不会检测到之前连接的设备
- c# - 继承是否包括扩展和实现?概念理解
- .net - 如何使用 PowerShell 查找 Active Directory 类的“Schema-Id-Guid”和属性的“System-Id-Guid”