Customise or reduce the height of the scale triangle legend bar using plot_gg() in rayshader package for 3D plot

Viewed 40

I am using the rayshader package to render a 3D plot with plot_gg() function. How can I customize or reduce the height of the scale triangle legend bar of the plot since it will cover the plot partly when we increase the argument scale (e.g. scale = 300, etc.).

My code is as following:

gg_mai = ggplot(mai_sff) +
  geom_sf(aes(fill = songuoi_km), lwd=0) +
  scale_fill_viridis("Mật độ người/km2", direction = -1, option = "viridis") +
  ggtitle("Họ Mai") +
  theme_bw()

plot_gg(gg_mai, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, 
       scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30)

Thank you so much!

This is the output I have

1 Answers

Well, you can define the key size in ggplot theme(). Without a reproducible example, I only added some arbitrary numbers. You may want to try different numbers on your side, even change the legend position.

gg_mai = ggplot(mai_sff) +
    geom_sf(aes(fill = songuoi_km), lwd=0) +
    scale_fill_viridis("Mật độ người/km2", direction = -1, option = "viridis") +
    ggtitle("Họ Mai") +
    theme_bw()+
    theme(
          legend.key.height = unit(2, "mm"),
          legend.key.width = unit(1, "mm")
    )      

plot_gg(gg_mai, multicore = TRUE, raytrace = TRUE, width = 7, height = 4, 
        scale = 300, windowsize = c(1400, 866), zoom = 0.6, phi = 30, theta = 30)
Related