1

Download the 1 km² attribute for the German Census 2011 immigrant rate, which has the German name Auslaender_A. Then download the data for the vacany rate (German name: Leerstandsquote) in the same raster resolution. Make sure to properly define missing values.
The function for downloading is z11::z11_get_1km_attribute() and the one for listing all attributes of this size z11::z11_list_1km_attributes(). There you can also see both of the data names.
immigrant_rate_1km <-
  z11::z11_get_1km_attribute(Auslaender_A)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum European Terrestrial Reference System 1989 in CRS
## definition
immigrant_rate_1km[immigrant_rate_1km <= -1] <- NA

vacany_rate_1km <-
  z11::z11_get_1km_attribute(Leerstandsquote)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition

## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum European Terrestrial Reference System 1989 in CRS
## definition
vacany_rate_1km[vacany_rate_1km <= -1] <- NA

immigrant_rate_1km
## class      : RasterLayer 
## dimensions : 867, 641, 555747  (nrow, ncol, ncell)
## resolution : 1000, 1000  (x, y)
## extent     : 4031500, 4672500, 2684500, 3551500  (xmin, xmax, ymin, ymax)
## crs        : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs 
## source     : memory
## names      : layer 
## values     : 0, 100  (min, max)
vacany_rate_1km
## class      : RasterLayer 
## dimensions : 867, 641, 555747  (nrow, ncol, ncell)
## resolution : 1000, 1000  (x, y)
## extent     : 4031500, 4672500, 2684500, 3551500  (xmin, xmax, ymin, ymax)
## crs        : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs 
## source     : memory
## names      : layer 
## values     : 0, 100  (min, max)

2

Crop both datasets to the extent of the city of Berlin.
You can use the osmdata:getbb() function to receive a proper polygon for this purpose. Make sure only to extract the multipolygon and to convert it to the EPSG:3035 CRS.
berlin <-
  osmdata::getbb("Berlin", format_out = "sf_polygon") %>% 
  .$multipolygon %>% 
  sf::st_transform(3035)

immigrant_rate_1km_berlin <-
  raster::crop(immigrant_rate_1km, berlin)

vacancy_rate_1km_berlin <-
  raster::crop(vacany_rate_1km, berlin)

3

That’s an open exercise: How would you try to conduct a basic correlational analysis of both raster data attributes?
Remember that you can extract the whole raster data as a simple vector using raster::getValues()
immigrant_rate_1km_berlin_z <-
  scale(immigrant_rate_1km_berlin)

vacancy_rate_1km_berlin_z <-
  scale(vacancy_rate_1km_berlin)


cor.test(
  raster::getValues(immigrant_rate_1km_berlin_z), 
  raster::getValues(vacancy_rate_1km_berlin_z),
  na.rm = TRUE
)
## 
##  Pearson's product-moment correlation
## 
## data:  raster::getValues(immigrant_rate_1km_berlin_z) and raster::getValues(vacancy_rate_1km_berlin_z)
## t = 4.1859, df = 1266, p-value = 3.037e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.06218765 0.17079069
## sample estimates:
##       cor 
## 0.1168384
where_both_are_high <- immigrant_rate_1km_berlin_z
where_both_are_high[
  immigrant_rate_1km_berlin_z <= 1 | vacancy_rate_1km_berlin_z <= 1
  ] <- 0
where_both_are_high[
  immigrant_rate_1km_berlin_z >= 1 & vacancy_rate_1km_berlin_z >= 1
  ] <- 1

raster::plot(where_both_are_high)