0

I´m trying to create a range map in R, which is supposed to show the occurrences of a specific tree species (Quercus cerris) in the world. For this, I use the BIEN database and the function BIEN_ranges_species(). I managed to create the map of the world, but the marks which show the occurrences of the trees cannot be seen. There might be a problem with the layer which shows the occurrences.

The following code is based on the example that BIEN recommends:

library(BIEN)
library(maps)
library(sf)

species_vector <- c("Quercus_cerris")
BIEN_ranges_species(species_vector)
BIEN_ranges_species(species_vector, match_names_only = TRUE)
temp_dir <- file.path("C:/Users/Nele/Documents/R_Karten")
BIEN_ranges_species(species = species_vector,
                directory = temp_dir)
BIEN_ranges_species("Quercus_cerris")
BIEN_ranges_species("Quercus_cerris",
                directory = temp_dir)

Quercus_test <- st_read(dsn = temp_dir,
                    layer = "Quercus_cerris")

plot(Quercus_test[1])
map('world', fill = TRUE, col = "grey")

plot(Quercus_test[1],
 col = "red",
 add = TRUE)

In addition, when I only plot the data for Quercus cerris, using this part of the code:

plot(Quercus_test[1],
 col = "red",
 add = TRUE)

there is also no visible data.

1
  • 1
    Looking through the vignette('BIEN_tutorial', package = 'BIEN') and quercus <- BIEN_ranges_species(species_vector, match_names_only = TRUE), then str(quercus)` shows there's 1 observation of Quercus cerris, which, as a point, might not show up on a world map. And there are no observations from BIEN_occurence_species. And if you have observations, you can add to the BIEN data.
    – Chris
    Commented May 14 at 17:43

1 Answer 1

1

As @Chris noted, your data are there, it is just that the features are not visible at 'world' scale. If you face this issue, here is a workflow that can be useful for troubleshooting/exploring your data:

library(BIEN)
library(maps)
library(sf)
library(ggplot2)

# Get Quercus_test metadata, note the bounding box values 
Quercus_test

# Simple feature collection with 1 feature and 2 fields
# Geometry type: MULTIPOLYGON
# Dimension:     XY
# Bounding box:  xmin: -123.4466 ymin: 38.80048 xmax: -72.64731 ymax: 49.07663
# Geodetic CRS:  WGS 84
#          species   gid                       geometry
# 1 Quercus_cerris 75854 MULTIPOLYGON (((-77.09406 3...

# Create world map sf, change CRS to match Quercus_test CRS
world <- map("world", fill = TRUE, col = "grey", wrap = c(-180, 180)) %>%
  st_as_sf() %>%
  st_transform(st_crs(Quercus_test))

# Using coords_sf(), 'zoom in' to Quercus_test sf with bounding box values as a basis
# linewidth value exaggerated for illustrative purposes
ggplot() +
  geom_sf(data = world, colour = "grey75") +
  geom_sf(data = Quercus_test, fill = "firebrick", colour = "firebrick", linewidth = 2) +
  coord_sf(xlim = c(-124, -72),
           ylim = c(38, 50)) +
  theme(panel.background = element_blank())

result

Not the answer you're looking for? Browse other questions tagged or ask your own question.