I love rasterVis::levelplot(margin=T) because its marginal graphics show the column (x) and row (y) summaries of the Raster object. I think it is very helpful to visualize the raster.

Package rasterVis is based on lattice. However, I was not familar with lattice. It's all my fault, but I have no time to learn complex lattice package.

Is there a way to make a map like rasterVis::levelplot(margin=T)?

Could ggplot2 do it?

Using the rasterVis package to make a complex plot is too hard for me as a non-English speaker.

f <- system.file("external/test.grd", package="raster")
r <- rast(f)

enter image description here

  • What do you mean "make a map"? You've made a map. Are you asking about adding other data onto the raster plot? Or adding things like a North arrow?
    – Spacedman
    Jan 11, 2023 at 22:09
  • Hi, Spacedman. I am asking if there is a another way to add line plot along the raster-plot's longitude and latitude. Just as the graph in my question description.
    – jackywang
    Jan 12, 2023 at 8:01
  • What's wrong with the way you've done it? Sure there's other ways, but why should we go to the bother of that when we have a way to do it already?
    – Spacedman
    Jan 12, 2023 at 9:08
  • Because lattice seems too hard for me(but I know it's my fault). For example, I could not add north arrow and scale bar with rasterVis::levelplot in multiple layers of stack(brick,spatraster), although the author of rasterVis gives method in his homepage(single layer). And plot the multiple layers gives too much space between facet plot, which affacts me much.
    – jackywang
    Jan 12, 2023 at 13:30
  • 1
    Well, it happens that I wrote a blog post about this recently, you may want to check it dieghernan.github.io/202212_tidyterra-hillshade-2
    – dieghernan
    Jan 12, 2023 at 18:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.