Created
December 8, 2017 15:14
-
-
Save marcosci/8d01f06adfeba47b55115da425e4147c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create landscapes | |
set.seed(5) | |
percolation_landscape <- nlm_percolation(100,100,0.4, resolution = 10) | |
random_landscape <- nlm_random(100,100, resolution = 10) | |
distagrad_landscape <- nlm_distancegradient(100, 100, origin = c(10,15,10,15), resolution = 10) | |
edgegradient_landscape <- nlm_edgegradient(100,100, 90, resolution = 10) | |
planar_landscape <- nlm_planargradient(100,100, resolution = 10) | |
randomRecCluster_landscape <- nlm_randomrectangularcluster(100, 100, minL = 8, maxL = 16, rescale = FALSE, resolution = 10) | |
randomElement_landscape <- nlm_randomelement(100,100, n = 90, resolution = 10) | |
randomCluster_landscape <- nlm_randomcluster(100,100, p = 0.5, resolution = 10) | |
mpd_landscape <- nlm_mpd(nCol = 100, nRow = 100, roughness = 0.7, resolution = 7.874017) | |
gaussian_linear_landscape <- nlm_gaussianfield(nCol = 100, nRow = 100, 35, direction = "linear", resolution = 10) | |
fBm_landscape <- nlm_fBm(nCol = 50, nRow = 50, H = 0.7, resolution = 20) | |
mosaic_landscape <- nlm_mosaicfield(nCol = 100, nRow = 100, n = 20, resolution = 10) | |
neighboorcluster_landscape <- nlm_neigh(nCol = 50, nRow = 50, p_neigh = 0.75, categories = 5, p_empty = 0.01, neighborhood = "Von-Neumann", resolution = 20, proportions =c(0.25, 0.05, 0.1, 0.3, 0.3)) | |
curds_landscape <- nlm_curds(p = c(0.33, 0.33, 0.33), s = c(32, 8, 4), ext = 1000) | |
poly_landscape <- nlm_polylands(nCol = 50, nRow = 50, germs = 20, resolution = 20) | |
# transform rasters to long data frame to use facets | |
## first transform to SpatialPixelsDataFrame to have a transformation to long format | |
percolation_spdf <- as(percolation_landscape, "SpatialPixelsDataFrame") | |
random_spdf <- as(random_landscape, "SpatialPixelsDataFrame") | |
distagrad_spdf <- as(distagrad_landscape, "SpatialPixelsDataFrame") | |
edgy_spdf <- as(edgegradient_landscape, "SpatialPixelsDataFrame") | |
planary_spdf <- as(planar_landscape, "SpatialPixelsDataFrame") | |
randomRecClustery_spdf <- as(randomRecCluster_landscape, "SpatialPixelsDataFrame") | |
randomElementy_spdf <- as(randomElement_landscape, "SpatialPixelsDataFrame") | |
randomClustery_spdf <- as(randomCluster_landscape, "SpatialPixelsDataFrame") | |
randomMPD_spdf <- as(mpd_landscape, "SpatialPixelsDataFrame") | |
gaussian_spdf <- as(gaussian_linear_landscape, "SpatialPixelsDataFrame") | |
fBm_spdf <- as(fBm_landscape, "SpatialPixelsDataFrame") | |
mosaic_spdf <- as(mosaic_landscape, "SpatialPixelsDataFrame") | |
neigh_spdf <- as(neighboorcluster_landscape, "SpatialPixelsDataFrame") | |
curds_spdf <- as(curds_landscape, "SpatialPixelsDataFrame") | |
poly_spdf <- as(poly_landscape, "SpatialPixelsDataFrame") | |
## transform to dataframes and give new row that contains name of the algorithm that produced the landscape | |
percolation_df <- as.data.frame(percolation_spdf) | |
percolation_df[,4] <- "Percolation" | |
random_df <- as.data.frame(random_spdf) | |
random_df[,4] <- "Random" | |
edgy_df <- as.data.frame(edgy_spdf) | |
edgy_df[,4] <- "Edge gradient" | |
distagrad_df <- as.data.frame(distagrad_spdf) | |
distagrad_df[,4] <- "Distance gradient" | |
planary_df <- as.data.frame(planary_spdf) | |
planary_df[,4] <- "Planar gradient" | |
randomRecClustery_df <- as.data.frame(randomRecClustery_spdf) | |
randomRecClustery_df[,4] <- "Random-rectangalur cluster" | |
randomElementy_df <- as.data.frame(randomElementy_spdf) | |
randomElementy_df[,4] <- "Random elements" | |
randomClustery_df <- as.data.frame(randomClustery_spdf) | |
randomClustery_df[,4] <- "Random cluster" | |
randomMPD_df <- as.data.frame(randomMPD_spdf) | |
randomMPD_df[,4] <- "Midpoint displacement" | |
gaussian_df <- as.data.frame(gaussian_spdf) | |
gaussian_df[,4] <- "Gaussian field" | |
names(gaussian_df)[1] <- "layer" | |
# gaussian_df[,c(2,3)] <- gaussian_df[,c(2,3)] / 100 | |
fbm_df <- as.data.frame(fBm_spdf) | |
fbm_df[,4] <- "Fractional Brownian Motion" | |
mosaic_df <- as.data.frame(mosaic_spdf) | |
mosaic_df[,4] <- "Mosaic random field" | |
names(mosaic_df)[1] <- "layer" | |
neigh_df <- as.data.frame(neigh_spdf) | |
neigh_df[,4] <- "Random Neighborhood" | |
curds_df <- as.data.frame(curds_spdf) | |
curds_df[,4] <- "Hierarchical Curdling" | |
poly_df <- as.data.frame(poly_spdf) | |
poly_df[,4] <- "Polygonal landscapes" | |
names(poly_df)[1] <- "layer" | |
# colnames(poly_df) <- c("value", "x", "y", "Type") | |
# ggplot2::ggplot(poly_df, aes(x=x, y=y)) + | |
# ggplot2::geom_raster(aes(fill=value), alpha=0.8) | |
## bind all of them together | |
nlm_df <- rbind(percolation_df, | |
random_df, | |
edgy_df, | |
distagrad_df, | |
planary_df, | |
randomRecClustery_df, | |
randomClustery_df, | |
randomElementy_df, | |
randomMPD_df, | |
gaussian_df, | |
fbm_df, | |
mosaic_df, | |
neigh_df, | |
curds_df, | |
poly_df) | |
## rename columns | |
colnames(nlm_df) <- c("value", "x", "y", "Type") | |
# Plot the rasters as facets | |
nlmr_bestiary <- ggplot2::ggplot(nlm_df, aes(x=x, y=y)) + | |
ggplot2::geom_raster(aes(fill=value), alpha=0.8) + | |
facet_wrap( ~ Type, ncol = 4, scales = "fixed") + | |
ggplot2::coord_equal() + | |
ggplot2::labs(x = "Easting", | |
y = "Northing") + | |
ggplot2::theme( | |
legend.position = "bottom", | |
text = ggplot2::element_text(color = "#22211d"), | |
axis.line = ggplot2::element_line(), | |
axis.ticks.length = ggplot2::unit(.15, "cm"), | |
axis.ticks = ggplot2::element_line(), | |
panel.background=element_blank(), | |
panel.border=element_blank(), # bg of the panelt | |
panel.grid.major = element_blank(), # get rid of major grid | |
panel.grid.minor = element_blank(), # get rid of minor grid | |
aspect.ratio=1, | |
plot.margin=unit(c(0,0,0,0),"mm") | |
) + | |
viridis::scale_fill_viridis( | |
option = "D", | |
direction = -1, | |
na.value = "transparent", | |
name = "Z", | |
guide = ggplot2::guide_colorbar( | |
direction = "horizontal", | |
barheight = ggplot2::unit(2, units = "mm"), | |
barwidth = ggplot2::unit(50, units = "mm"), | |
draw.ulim = FALSE, | |
title.position = "top", | |
title.hjust = 0.5, | |
label.hjust = 0.5 | |
)) + | |
coord_capped_cart( | |
xlim = c(0, 1000), ylim = c(0, 1000), left = "both", bottom = "both") | |
nlmr_bestiary <- nlmr_bestiary + theme(text = element_text(size = 20), | |
axis.text = element_text(size = 13), | |
strip.text = element_text(size = 11, face = "bold"), | |
legend.text=element_text(size=11)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment