Search code examples
rdataframerowsrasterboxplot

Multiple boxplots of rasters with differing rows


I am trying to create boxplots for rasters of magnitudes of breaks in trend of vegetation indices across four study sites. I am trying to get the 4 boxplots into one graph, but since the study sites are all of different sizes I am receiving the error:

arguments imply differing number of rows: 99855, 108240...

The code I am using is:

boxplot(data.frame(Y1_EVI=values(Y1_EVI), Y2_EVI=values(Y2_EVI), 
                   G1_EVI=values(G1_EVI), G2_EVI=values(G2_EVI)), 
        main = "EVI", ylab = "Magnitude", outline = FALSE)

It works with just Y1 and Y2 as they coincidentally had the same dimensions, just different extents. Is there a way to get around this differing number of rows issue in the data.frame? Any help would be appreciated and please let me know if more detail is needed.

Thank you!


Solution

  • Assign your values to a list rather than a data frame as data frames require equal length of vectors to be combined. Then call boxplot on the list.

    For example:

    W <- rnorm(10)
    X <- rnorm(20) 
    Y <- rnorm(30) 
    Z <- rnorm(40) 
    data_list <- list(Y1_EVI=W, Y2_EVI=X, G1_EVI=Y, G2_EVI=Z)
    boxplot(data_list, main = "EVI", ylab = "Magnitude", outline = FALSE)
    

    enter image description here