Can not remove the title of subplot

raster
#1

I read the 22 raster files and made the stack of all and then cropped them using shapefile (shp_Bhote). I divided the 22 rasters into four groups according to different time raster. I estimated the frequency of the values in raster for each group and made a four stack from them. And then I plotted the four different raster stack using level plot and layout function. However, the title of each plot on the graph comes automatically like layer.1, layer.2, layer.3, and layer.4. I want to remove this title from my plot, however, I can not figure out the issue. Help will be highly appreciated. I am sorry for the bad question.
Here is the code that I used for the plot.
List of tif files

library(raster)
library(sp)
library(rgdal)
library(lattice)
library(RColorBrewer)
library(rasterVis)
list_tif=list.files(getwd(),pattern=".tif")
a=stack(list_tif)
a_subset = subset(a, 1:8)
b_subset = subset(a,9:16)
c_subset = subset(a, 17:22)
shp_Bhote <- readOGR(dsn = ".", layer = "Bhote_Kosi")
Bhote = crop(a,extent(shp_Bhote), snap = "out")
Bhote_a = crop(a_subset,extent(shp_Bhote), snap = "out")
Bhote_b = crop(b_subset,extent(shp_Bhote), snap = "out")
Bhote_c = crop(c_subset,extent(shp_Bhote), snap = "out")
count_lake_Bhote=sum(Bhote)
count_lake_Bhote_a=sum(Bhote_a,na.rm=T)
count_lake_Bhote_b=sum(Bhote_b,na.rm=T)
count_lake_Bhote_c=sum(Bhote_c,na.rm=T)
frequency_Bhote=count_lake_Bhote/nlayers(Bhote)*100
frequency_Bhote_a=count_lake_Bhote_a/nlayers(Bhote_a)*100
frequency_Bhote_b=count_lake_Bhote_b/nlayers(Bhote_b)*100
frequency_Bhote_c=count_lake_Bhote_c/nlayers(Bhote_c)*100
#####remove NA Values
frequency_Bhote[frequency_Bhote==0]<-NA
frequency_Bhote_a[frequency_Bhote_a==0]<-NA
frequency_Bhote_b[frequency_Bhote_b==0]<-NA
frequency_Bhote_c[frequency_Bhote_c==0]<-NA
Bhote_stack <- stack(frequency_Bhote_a, frequency_Bhote_b, frequency_Bhote_c, frequency_Bhote)
breaks <- seq(0, 100, by=1)
cols<-colorRampPalette(c("cyan","blue","pink","red"))(length(breaks)-1)
levelplot(Bhote_stack,colorkey = TRUE, layout=c(4, 1),scales=list(x=list(draw=FALSE),y=list(draw=FALSE)), at=breaks, col.regions=cols, margin  = F))+
  layer(sp.polygons(shp_Bhote))

0 Likes

#2

Welcome to the community!

Can you please turn this into a REPRoducible EXample? From the way you have posted your code, it's not clear to me which packages you're using, or what is the dataset leading to frequency_Bhote_a etc.

In case you don't know how to make a reprex, here's a great link:

1 Like

#3

I appreciate your effort, but unfortunately, it's not reproducible. It requires the .tif files in the working directory, and we don't have them.

You won't be able to upload those files, but you can share them after uploading to some cloud storage, or to imgur.

Check the following post from SO. It makes me think that setting names.attr = NULL may do the trick for you.

1 Like

#4

I tried to use the function names.attr = NULL but it shows the error as follows.
levelplot(Bhote_stack,colorkey = TRUE, layout=c(4, 1),scales=list(x=list(draw=FALSE),y=list(draw=FALSE)), at=breaks, col.regions=cols, main = "Example", names.attr= NULL), layer(sp.polygons(shp_Bhote))
Error in .local(x, data, ...) :
Length of names.attr should match number of layers.

Similarly, I tried the following codes also shows the error
levelplot(Bhote_stack[[1:4]],colorkey = TRUE, layout=c(4, 1),scales=list(x=list(draw=FALSE),y=list(draw=FALSE)), at=breaks, col.regions=cols, main = "Example", names.attr= 1:4), layer(sp.polygons(shp_Bhote))
Error in valid.data(rep(units, length.out = length(x)), data) :
no string supplied for 'strwidth/height' unit

0 Likes

#5

I can't access it. It says: The folder ‘/R_frequency_plot’ doesn’t exist.

Can you please check this? Alternatively, I think it'll be easier if you upload to imgur.

0 Likes

#6

I kept the file in imgur. Still not sure whether you can access or not?
https://mohanchand.imgur.com/all

0 Likes

#7

Sorry, once again I'm unable to access it. Imgur shows: Zoinks! You've taken a wrong turn.

Let me present you a way using the example from the aforementioned SO thread. I'm sure that you'll be able to modify it for your own problem.

What I did below is plotted it accepting the defaults at first, and then used ""'s as names. Compare the two pictures.

require(rasterVis)
#> Loading required package: rasterVis
#> Loading required package: raster
#> Loading required package: sp
#> Loading required package: lattice
#> Loading required package: latticeExtra
#> Loading required package: RColorBrewer

layers <- c(1:4)
s2 <- stack()

for (i in layers) {
  r <- raster(nrows=100, ncols=100)
  r[] <- sample(seq(from = 1, to = 6, by = 1), size = 10000, replace = TRUE)
  rasc <- ratify(r)
  rat <- levels(rasc)[[1]]
  rat$legend <- c("A","B","C","D","E","F")
  levels(rasc) <- rat
  s2 <- stack(s2, rasc)
}

# using default names
levelplot(s2, col.regions=rev(terrain.colors(6)),main = "example")


# using blanck names
levelplot(s2, col.regions=rev(terrain.colors(6)),main = "example", names.attr=rep("",4))

Created on 2019-03-21 by the reprex package (v0.2.1)

Hope this helps!

0 Likes

#8

Yes, this helped me to remove the title of the subplot. Thank you very much for your effort. I am wondering about the sizes of the subplot. I expected the increase in the size of subplot by removing the title. Space still seems unused.

Thank you,

0 Likes

#9

Sorry. I can't help you with that. I hope someone else will.

1 Like

closed #10

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes