Home > Back-end >  Removing Legend in R
Removing Legend in R

Time:06-15

I have created a map showing forest area place using the code below:-

library(raster)
RupandehiLULC10<-raster('C:/Users/lenovo/Desktop/EM/RupandehiLULC.tif')
plot(RupandehiLULC10)
RupandehiLULC10
RupandehiFOG10<-cbind(c(1,2,3,4,5,6,7),
          c(1,2,3,4,5,5,5))
reclass<-reclassify(RupandehiLULC10,rcl=RupandehiFOG10)
plot(reclass,
 col=c("grey","grey","grey","grey","green","green","green"))
plot(reclass,
 col=c("grey","grey","grey","grey","green","green","green"), axes=FALSE,
 main="Forest Area of Rupandehi in 2010")
legend("bottomright",
   legend=c("Forest","Other Land"),
   fill=c("green","grey"),
   border=FALSE,
   bty="n")

The result I obtained is:- enter image description here

But, I want the map to be displayed only with legend (present at top-bottom) i.e. Forest and Other Land and want to omit the legend present as class from 1-5 outside of the map border. How this can be done???

CodePudding user response:

First of all, we don't have your data so I am not sure if it works. But you can set legend = FALSE in your plot function like this:

library(raster)
plot(reclass,
     col=c("grey","grey","grey","grey","green","green","green"), legend=FALSE)
plot(reclass,
     col=c("grey","grey","grey","grey","green","green","green"), axes=FALSE,
     main="Forest Area of Rupandehi in 2010", legend=FALSE)
legend("bottomright",
       legend=c("Forest","Other Land"),
       fill=c("green","grey"),
       border=FALSE,
       bty="n")
  • Related