Hi Alex,
thank you so much for your answer! The part about plot with add=TRUE helped a lot - don't know why I didn't do it like that, especially since I had something similar in a previous attempt. I also managed to solve the problem with the overlapping legends:
plot(habitatmap, col = grey.colors(60, start=0, end=1), legend=FALSE, axes=FALSE)
plot(habitatmap, legend.only=TRUE, col = grey.colors(60, start=0, end=1),
horizontal=TRUE,
legend.args=list(text='Habitat Suitability', side=1, font=2, line=2.5, cex=0.8),
)
plot(r, legend=FALSE, axes=FALSE, add = TRUE)
plot(r, legend.only=TRUE, # colours work
horizontal=FALSE,
legend.args=list(text='Probability for Territory Presence', side=4, font=2, line=2.5, cex=0.8),
)
Unfortunately, I am still completely lost when it comes to extent and projection. Basically, I want to combine two objects, a SpatialPolygonsDataFrame and a RasterLayer. They look like this:
>Borders
class : SpatialPolygonsDataFrame
features : 16
extent : 5.866251, 15.04181, 47.27012, 55.05653 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
variables : 10
names : GID_0, NAME_0, GID_1, NAME_1, VARNAME_1, NL_NAME_1, TYPE_1, ENGTYPE_1, CC_1, HASC_1
min values : DEU, Germany, DEU.1_1, Baden-Württemberg, Bavaria, NA, Freie Hansestadt, State, 01,
DE.BE max values : DEU, Germany, DEU.9_1, Thüringen, Thuringia, NA, Land, State, 16,
DE.TH > TerritoryProb1[[4]] # this is my data, mean over many replicates of out_terr
class : RasterLayer
dimensions : 867, 643, 557481 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0.5, 643.5, 0.5, 867.5 (xmin, xmax, ymin, ymax)
crs : NA
source : memory
names : Year2026
values : 0, 1 (min, max)
Since my RasterLayer doesn't have a projection (or does it?) I guess I would need to project it somehow. While making sure that the projection fits the one of the SpatialPolygonsDataFrame. In the original ascii files I have extra information:
xllcorner 3279642.6028546
yllcorner 5237006.2964934
Do you think there is an easy way, preferably without using ArcGIS, to get extent and projection from this? Because if not, I think I will just give up on the borders and count on people's imagination of the country's geography..
And I am sorry about not including a reproducible example, I don't know how I could do that without uploading way too much data..
Cheers, Clara