st_normalize.sfc(x,c(x_range [1],y_range [1],x_range [2],y_range [2])中的错误:域必须具有正范围 [英] 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

查看:74
本文介绍了st_normalize.sfc(x,c(x_range [1],y_range [1],x_range [2],y_range [2])中的错误:域必须具有正范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

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

I am using ggplot2 geom_point to map animal location points by week. As a basemap, I am using a shapefile from my computer.

以下是我的数据示例:

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的示例:

Here is an example of the ggplot without the basemap added:

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

问题:

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

The above code worked before I updated R and RStudio to the newest version (last week). Now, these maps will not draw, and I get the following error:

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 .就像我说的那样,此代码在更新之前一直有效.任何帮助将不胜感激.

I have not moved my shapefiles to another folder on my computer and they imported into RStudio correctly. I also have defined coord_sf correctly. Like I said, this code worked until the update. Any help would be appreciated.

推荐答案

我对您的代码做了一些小的修改,并且能够使用下面显示的r版本(R版本3.6.3)获得此图.这就是您期望看到的吗?

I made some minor modifications to your code and was able to get this plot using the r version shown below (R version 3.6.3). Is this is what you were expecting to see?

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]

[![My Plot][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

这篇关于st_normalize.sfc(x,c(x_range [1],y_range [1],x_range [2],y_range [2])中的错误:域必须具有正范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆