0

I am trying to create a Spatial point data frame from a .csv file. It works (in general), but the output is mirrored, so the rastered map I create with it is "upside down". I used this approach here (Creating a RasterLayer) to create the raster.

I can't figure out what the problem is. Any help would be much appreciated!

base <- read.csv(file="Ancylus_Cleaned_Coordinates.csv", header=T, sep="\t")
head(base)

#latitude longitude      species
#1 40.55000  -8.16000 Afluviatilis
#2 40.22000  -8.15000 Afluviatilis
#3 54.43584  -8.12788 Afluviatilis

spdf <- SpatialPointsDataFrame( base[ c("latitude" , "longitude") ], data = data.frame( base$species ),  proj4string = CRS("+proj=longlat +datum=WGS84") )

r <- raster(extent(spdf))
r

Then I set the resolution of the raste

res(r) <- 1

Expand it

r <- extend(r, extent(r)+5)

Draw my subsamples

acsel <- gridSample(base, r, n=1)

And plot the results

p <- rasterToPolygons(r)
plot(p, border='gray')
points(afc)
Community
  • 1
  • 1

1 Answers1

1

You could try function flip from raster package.

library(raster)

r <- raster(nrow=18, ncol=36)
r[] <- 1:ncell(r)

par(mfrow = c(1, 2))
plot(r)
plot(flip(r, direction = "y"))

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197