geocompx / geocompr

Geocomputation with R: an open source book
https://r.geocompx.org/
Other
1.54k stars 583 forks source link

Review 4 #302

Closed Robinlovelace closed 5 years ago

Robinlovelace commented 6 years ago

Review 1, chs 10,14-15

Chapter 10

Geoalgorithms, such as those we encountered in Chapter 9, are algorithms that take geographic data in and, generally, return geographic results (alternative terms for the same thing include GIS algorithms and geometric algorithms). That may sound simple but it is a deep subject with an entire academic field, Computational Geometry, dedicated to their study (Berg et al. 2008) and numerous books on the subject. O’Rourke (1998), for example, introduces the subject with a range of progressively harder geometric algorithms using reproducible and freely available C code.

I think that addresses the issue here but if you have any other suggestions on how to improve this section please let us know with reference to the latest version, which can be found here: https://geocompr.robinlovelace.net/algorithms.html#geometric-algorithms

Chapter 14

Chapter 15

Review 2, chs 10,14-15

Chapter 10

The text was a response to a previous review comment that said having your data loaded is a pre-requisite. However we agree it sounded strange. Updated now to:

It assumes you have an understanding of the geographic classes introduced in Chapter 2 and how they can be used to represent a wide range of input file formats (see Chapter 7).

Chapter 14

comm %>% rowSums %>% range
[1] 0.006 132.700

Perhaps this is due to overlapping cover between individual plants, in which case this should be mentioned to avoid confusion. This should probably also be clarified in ?comm.

- Yes, overlapping covers are in fact the reason for values >100%. We have added this information to the text and also to ?comm. Thanks for noting!

comm %>% rowMeans %>% mean
[1] 0.3809451

I realize that some types of analyses cannot accept “empty” sites; however it is easy to remove those sites prior to analysis, with the added benefit that the analyst is reminded of the reality that such sites actually exist and making a conscious decision whether to include them.

- Yes, I absolutely agree, I generally would not dismiss "empty" sites. Unfortunately, ordination techniques such as NMDS and DCA cannot handle empty sites. But I agree again with you that we should make this an obvious decision of the data analyst. Hence, I have added the empty sites to the community matrix, and we dismiss them now explicitly in the text.

open_app()
Error in py_run_string_impl(code, local, convert) :
ImportError: No module named qgis.core

As far as I can tell this is due to the fact that the RQGIS package cannot work with this version of QGIS yet – https://github.com/jannes-m/RQGIS/issues/97

- Yes, the reason is that RQGIS is so far not working with QGIS3 but it will, just give me a bit more time (in fact I have already made RQGIS working with QGIS3 but had not have the time yet to implement it properly). You are also right that we should provide the reader with the output of the RQGIS processing. Hence, we have added ep to spDataLarge as a convenience to the reader.

- "Better" refers to a larger part of the variance explained by 2 axes. That presence-absence data yields better results compared to percentage data is explored in more detail in the Exercise section of the chapter.

library(lattice)
library(vegan)
#> Loading required package: permute
#> This is vegan 2.5-2
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.3.1, proj.4 5.1.0

data("random_points", "comm", package = "RQGIS")
data("ep", package = "spDataLarge")
random_points[, names(ep)] = raster::extract(ep, as(random_points, "Spatial"))

# presence-absence matrix
pa = decostand(comm, "pa")  # 100 rows (sites), 69 columns (species)
# keep only sites in which at least one species was found
pa = pa[rowSums(pa) != 0, ]  # 84 rows, 69 columns

my_url = "https://raw.githubusercontent.com/Robinlovelace/geocompr/master/extdata/14-nmds.rds"
# my_file = tempfile(fileext = ".rds")
# download.file(my_url, my_file, method = "curl")
# readRDS(my_file)
nmds = readRDS(gzcon(url(my_url)))
elev = dplyr::filter(random_points, id %in% rownames(pa)) %>% 
  dplyr::pull(dem)
# rotating NMDS in accordance with altitude (proxy for humidity)
rotnmds = MDSrotate(nmds, elev)
# extracting the first two axes
sc = scores(rotnmds, choices = 1:2)

xyplot(scores(rotnmds)[, 2] ~ scores(rotnmds)[, 1], pch = 16, 
       col = "lightblue", xlim = c(-3, 2), ylim = c(-2, 2),
       xlab = list("Dimension 1", cex = 0.8), 
       ylab = list("Dimension 2", cex = 0.8),
       scales = list(x = list(relation = "same", cex = 0.8),  
                     y = list(relation = "same", cex = 0.8),
                     # ticks on top are suppressed
                     tck = c(1, 0),  
                     # plots axes labels only in row and column 1 and 4
                     alternating = c(1, 0, 0, 1),    
                     draw = TRUE),
       # we have to use the same colors in the legend as used for the plot
       # points
       par.settings = simpleTheme(col = c("lightblue", "salmon"), 
                                  pch = 16, cex = 0.9), 
       # also the legend point size should be somewhat smaller
       auto.key = list(x = 0.7, y = 0.9, text = c("unrotated", "rotated"), 
                       between = 0.5, cex = 0.9),
       panel = function(x, y, ...) {
         # Plot the points
         panel.points(x, y, cex = 0.6, ...)
         panel.points(x = scores(nmds)[, 1], 
                      y = scores(nmds)[, 2], 
                      col = "salmon", pch = 16, cex = 0.6)
         panel.arrows(x0 = scores(nmds)[, 1], 
                      y0 = scores(nmds)[, 2],
                      x1 = x,
                      y1 = y, 
                      length = 0.04,
                      lwd = 0.4)
       })

Created on 2018-09-25 by the reprex package (v0.2.1)

- Done that. Thanks!

Chapter 15

Review 3

Chapter 10

Chapter 14

Chapter 15

You were! Apologies for that but John suggested not sending incremental updates, which probably made your life easier. Comments very much appreciated.

Robinlovelace commented 5 years ago

👍