# \donttest{
library(sdcSpatial)
library(raster)
data(enterprises)
# create a sdc_raster from point data with raster with
# a resolution of 200m
production <- sdc_raster(enterprises, variable = "production"
, r = 200, min_count = 3)
print(production)
# plot the raster
zlim <- c(0, 3e4)
# show which raster cells are sensitive
plot(production, zlim=zlim)
# but we can also retrieve directly the raster
sensitive <- is_sensitive(production, min_count = 3)
plot(sensitive, col = c('white', 'red'))
# what is the sensitivy fraction?
sensitivity_score(production)
# or equally
cellStats(sensitive, mean)
# let's smooth to reduce the sensitivity
smoothed <- protect_smooth(production, bw = 400)
plot(smoothed)
# let's smooth to reduce the sensitivity, with higher resolution
smoothed <- protect_smooth(production, bw = 400, smooth_fact=4, keep_resolution=FALSE)
plot(smoothed)
# what is the sensitivy fraction?
sensitivity_score(smoothed)
# let's remove the sensitive data.
smoothed_safe <- remove_sensitive(smoothed, min_count = 3)
plot(smoothed_safe)
# let's communicate!
production_mean <- mean(smoothed_safe)
production_total <- sum(smoothed_safe)
# and create a contour plot
raster::filledContour(production_mean, nlevels = 6, main = "Mean production")
# generated with R 3.6 >=
#col <- hcl.colors(11, rev=TRUE)
col <- c("#FDE333", "#C2DE34", "#7ED357", "#00C475", "#00B28A", "#009B95"
, "#008298", "#006791", "#274983", "#44286E", "#4B0055"
)
raster::filledContour(production_total, nlevels = 11
, col = col
, main="Total production")
# }
Run the code above in your browser using DataLab