0

While plotting levelplot I want to add mean and median if the plot. manually calculating and adding is tedious. any other way?

p1=levelplot(R_land, par.settings=mapTheme, at=my.brks, colorkey=myColorkey , 
margin=F,main=list('IMD'),xlab = 'Mean=0.728
Median=0.368')
print(p1) 

also hopefully not as a label but top right of the plot.

data:

head(Gm,n=10)
         x     y       Gm
 1:  66.50 38.50 1.611716
 2:  66.75 38.50 1.825812
 3:  67.00 38.50 1.873785
 4:  67.25 38.50 1.936212
 5:  67.50 38.50 2.025188
 6:  67.75 38.50 1.982969
 7:  68.00 38.50 1.696595
 8:  68.25 38.50 1.740960
 9:  68.50 38.50 1.774679
10:  68.75 38.50 1.866798

R_land<-rasterfromXYZ(Gm)
hat6ytrs
  • 11
  • 3
  • Sample data, reproducible question please. – r2evans Nov 18 '22 at 13:19
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 18 '22 at 14:39
  • @r2evans I was unsure what to include as its a raster data with too many points. hope this helps. – hat6ytrs Nov 19 '22 at 23:44
  • I think you can explore ggstatplot package, or patchwork. Both are based on ggplot framework. Patchwork will allow you to "inset" an image with other. – Eva Nov 20 '22 at 00:34
  • @hat6ytrs, that's often a hard thing to do well with your own data, either due to non-trivial data, proprietary data, or other things. A good way may be to create sample data that approximates what you have, enough so that when you are provided a suggested answer(s), you can easily adapt it to your real data. For instance, `?lattice` includes code to generate data to demonstrate how to use the function; you can copy that (exactly) or mimic its intent to provide something representative and reproducible. – r2evans Nov 20 '22 at 00:58

0 Answers0