azizka / sampbias

Sampbias is a method and tool to 1) visualize the distribution of occurrence records and species in any user-provided dataset, 2) quantify the biasing effect of geographic features related to human accessibility, such as proximity to cities, rivers or roads, and 3) create publication-level graphs of these biasing effects in space.
33 stars 9 forks source link

The number of biases in plot.sampbias() needs to be a factor of 1000 #15

Open JDiazCalafat opened 9 months ago

JDiazCalafat commented 9 months ago

Hi,

First of all, this is a great package, thanks!

Playing around, I have found that it is not possible to use the function plot.sampbias() when the number of biases to be plotted is not a factor of 1000. Specifically, I was trying to plot biases based on three spatial features, and I got the following error message:

Warning: longer object length is not a multiple of shorter object lengthError in data.frame(dist = plo2_dist, rate = plo2_w[4] * exp(-plo2_w[5:(length(plo2_w) - : arguments imply differing number of rows: 1000, 3

To solve this, I had to change the current line 48 in plot.sampbias.R, which establishes the number of points to be plotted along the X axis from: plo2_dist <- seq(1,1000,length.out=1000)

to: plo2_dist <- seq(1,999,length.out=999)

This way, since 999 is a multiple of 3, the code worked with no error messages.

I think that this issue should be easy to fix adding an if statement. Plots do not change perceptibly when the _plo2dist value is 1000 vs. 999. By fixing this, the code would allow to plot 1 to 5 biases (it would again not work for 6 biases, but that may be too many to plot anyway).

Cheers and congratulations again on the package!