I would like to add a title to a plotRGB output.
#create random raster stack
r1 <- raster(nrow=5, ncol=5)
values(r1) <- 1:25
r2 <- r3 <- r1
RGB_stack <- stack(r1, r2, r3)
I have tried:
# Create an RGB image from the raster stack
plotRGB(RGB_stack, r = 1, g = 2, b = 3,
axes=TRUE, main="My Title")
plotRGB(RGB_stack, r = 1, g = 2, b = 3,
axes=TRUE, addfun="(title='Test title')")
I have tried to turn the axes on and off. I am not sure what else to try to make this work.
UPDATE: based upon feedback below i figured out that
#Create an RGB image from the raster stack
plotRGB(RGB_stack, r = 1, g = 2, b = 3,
axes=TRUE, main="My Title")
works IF you have cleared out previous plots that might have the axes turned off. However i'd still like the plot to be an image with no axes ticks and just a title.
Your first guess works for me:
plotRGB(RGB_stack, r = 1, g = 2, b = 3,
axes=TRUE, main="My Title")
After discussion, it is true that putting axes=FALSE also removes the title. As a workaround, you could try to plot the axis and labels in white. I also add a white box.
original_par <-par() #original par
par(col.axis="white",col.lab="white",tck=0)
plotRGB(RGB_stack, r = 1, g = 2, b = 3,
axes=TRUE, main="My Title")
box(col="white")
par(original_par) # go back to original par
I also did not want axes on my plotRBG plot.
I hacked the legend function to get around this without changing my par() parameters, because I'm making a multi-box layout.
legend("top", legend = NA, title = expression(bold("(My title)")), bty = "n", cex = 1.3)
I was having the same problem. The legend hack did not work for me, so I used the graphics::title function in my par().
title(main = "My title", cex.main = 1.3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With