Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotRGB add title

Tags:

r

raster

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.

like image 425
Leah Wasser Avatar asked Nov 10 '15 18:11

Leah Wasser


3 Answers

Your first guess works for me:

plotRGB(RGB_stack, r = 1, g = 2, b = 3,
        axes=TRUE, main="My Title")

enter image description here

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

enter image description here

like image 113
Pierre Lapointe Avatar answered Nov 19 '22 06:11

Pierre Lapointe


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)
like image 3
Nova Avatar answered Nov 19 '22 04:11

Nova


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)
like image 1
ESELIA Avatar answered Nov 19 '22 05:11

ESELIA