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

Viewed 636

Background:

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

Here is an example of my data:

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

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")

Problem:

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 

What I've tried:

  • Restarted R and RStudio
  • Re-installed and updated ggplot2 and dplyr

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.

1 Answers

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")

[![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
Related