1

I want to plot some sf data, similar to this example:

library (sf)

fishnet <- st_make_grid ()
n <- length (fishnet)
vals <- rlnorm (n)
fishnet <- st_sf (fishnet)
fishnet <- cbind (fishnet, vals)

c_ramp <- colorRampPalette (c ("azure", "yellow", "red"))
plot (fishnet, pal  = c_ramp)

I want to use a log scale for the legend and color scheme, but the plot function doesn't seem to support log scale out of the box. Is there any painless way around that?

karpfen
  • 2,307
  • 1
  • 17
  • 32

2 Answers2

1

According to the sf package documentation, the plot method for sf objects have and argument (or parameter) called logz, which has as default FALSE. If you set logz = TRUE, the variable that you are trying to plot is displayed on the log-scale.
You can find an example below:

plot(fishnet["vals"], logz = TRUE)

lcgodoy
  • 111
  • 4
0

In looking at the code underlying the plot_sf function, it seems like the path of least resistance is to just create a new column with the log transformed values. If one could call y separately you could transform the values on the fly but, currently the plot generic is not written in that way.

fishnet$log.vals <- log(fishnet$vals)
plot(fishnet[,"log.vals"], pal  = c_ramp)
Jeffrey Evans
  • 31,750
  • 2
  • 47
  • 94