r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
582 stars 130 forks source link

Custom breaks not handled correctly when plotting #702

Closed s-kganz closed 1 year ago

s-kganz commented 1 year ago

Hello,

The documentation for lidR::plot says that the breaks argument can be

either a numeric vector with the actual breaks, or a name of a method accepted by the style argument of classIntervals

But when I try to supply my own breaks, an error is returned. To reproduce:

library(lidR)

LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile)

plot(las, axis=TRUE, legend=TRUE, breaks=seq(0, 40, by=2))
#> Error in classInt::classIntervals(colorattr, min(nbreaks, nunique), breaks) : 
#>  0 unknown

Looking at the relevant function in classInt, it seems that one can specify the style as "fixed" and then pass the breaks as a separate argument:

mybreaks <- seq(0, 40, by=2)
classInt::classIntervals(las$Z, length(mybreaks), style="fixed", fixedBreaks=mybreaks)
#> style: fixed
#>  [0,2)   [2,4)   [4,6)   [6,8)  [8,10) [10,12) [12,14) [14,16) [16,18) [18,20) [20,22) [22,24) 
#>   9446     633     769    1087    1570    2164    3025    4052    4104    3847    3482    2098 
#> [24,26) [26,28) [28,30) [30,32) [32,34) [34,36) [36,38) [38,40] 
#>   1004     265      70      39       2       0       0       0 

Unless I'm missing something, this should be fixable with a small change in plot.

Jean-Romain commented 1 year ago

Fixed, thank you for reporting