Extract the results plotted in the margin of the levelplot function

How can i extract the results plotted in the margin of the levelplot function?

Or is there a function that does the same thing?

I'm searching for something like a table...

Best regards,

    library(raster)
    library(rasterVis)
    library(gridExtra)
    
    f <- system.file("external/test.grd", package="raster")
    r <- raster(f)
    x <- levelplot(r, margin=T)

enter image description here

Upvotes: 0

Views: 94

Answers (1)

Oscar Perpi&#241;&#225;n
Oscar Perpi&#241;&#225;n

Reputation: 4511

From the help page of rasterVis::levelplot:

[These] marginal graphics show the column (x) and row (y) summaries of the Raster* object. The summary is computed with the function mean.

You should use the raster::zonal function to compute them:

rx <- init(r, 'x')
mx <- zonal(r, rx, FUN = mean)
plot(mx, type = 'l')

Upvotes: 1

Related Questions