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?


2 Answers 2


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)

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)

  • 4
    This answer is quite sparse, and could use a documentation reference and a few sentences to frame it as a high-quality answer.
    – Vince
    May 14, 2020 at 0:40
  • Just included the requested information.
    – lcgodoy
    May 14, 2020 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.