0
library(raster)
library(rasterVis)
 r <- raster(nrows=10, ncols=10)
 r <- setValues(r, 1:ncell(r))
levelplot(r)

I want to put a word (a text) that is "Original map" under the xlab "Longitude"

Is this possible?

temor
  • 935
  • 2
  • 10
  • 26
  • `levelplot(r, xlab = 'Longitude\nOriginal map')` works although it changes the scaling a bit. not sure of the proper way to do this for this package – rawr Aug 08 '15 at 14:09
  • I do not want to use xlab because it changes the scale so i want to put the text on the plot without changing anything – temor Aug 08 '15 at 14:11
  • 2
    I don't understand what do you mean with "changes the scale". I have used the solution of @rawr and it works correctly for me. On the other hand, you could try `levelplot(r, margin = FALSE, sub = 'Original Map')` if you don't need the marginal plots. – Oscar Perpiñán Aug 10 '15 at 08:00

2 Answers2

0

This is a manual solution, but you can use mtext to place text around margins with line and adj parameters to put it where you want (or text).

plot.new()  # open new plot
 r <- raster(nrows=10, ncols=10)
 r <- setValues(r, 1:ncell(r))
levelplot(r)

mtext("Original map", 1, line=-3.4, adj=0.4)

enter image description here

Rorschach
  • 31,301
  • 5
  • 78
  • 129
0

With the grid library you can place text, as well.

plot.new()  # open new plot
 r <- raster(nrows=10, ncols=10)
 r <- setValues(r, 1:ncell(r))
levelplot(r)
library(grid)
trellis.focus("panel", 1, 1, clip.off = TRUE,highlight=TRUE)
grid.text("Hello World!", x = 0.5, y = 0.5,gp = gpar(fontsize = 6))
trellis.unfocus()
Agustin
  • 51
  • 2