I have to plot in the same graph something like this:

enter image description here

Then, I have elements from SpatialPolygonDataFrame class and others elements from SpatialGridDataFrame class. When I try to plot them in the same graph only get this error:

Error in `[[<-.data.frame`(`*tmp*`, i, value = c(52.6195687909829, 52.6845097109409,  : 
  replacement has 64 rows, data has 672. 

However, I converted all elements to SpatialPolygonDataFrame class, but it does not work.

I've watched the data and I think that the problem is the size of the elements (row, columns) but I'm not sure. I do not how to do it.

This is a example of my routine.

# Interpolation kriging
k_066_1617H <- krige(data066_1617H$Vtec~1,locations = data066_1617H,newdata = gridpolygon2,model = Ajuste2) 


#[1] "SpatialPolygonsDataFrame"
#[1] "sp"

Then, read a TIFF file

land <- readGDAL("image.tif")  

#[1] "SpatialGridDataFrame"
#[1] "sp"

land <- Grid2Polygons(land) # Transform into SpatialPolygonDataFrame


#[1] "SpatialPolygonsDataFrame"
#[1] "sp"

Construct a vector with land and k_066_1617H for plot with spplot

zn.k_066_1516H = land

zn.k_066_1617H = k_066_1617H
zn = land
zn[["a"]] = land[["z"]]
zn[["b"]] = zn.k_066_1617H[["var1.pred"]]

Here, is the problem. Maybe the size of elements is the problem.

land has 28 rows and 24 columns and k_066_1617H has 3752 rows.

spplot(zn, c("a","b"),
            main = "Santander, VTEC día 066",
            #names.attr = c("Prueba","18 - 19", "16 - 17"),
            sp.layout = c('sp.points', santos.coord, col='red', pch=19),
            scales=list(draw = TRUE),
  • 3
    You really need to give us some sample code that creates objects of the right class and shows the error, otherwise we'll be forever guessing! Or you have to supply us with your objects - maybe upload them to a dropbox shared file or similar. – Spacedman Jan 26 '16 at 10:15
  • 1
    When you say "a plot like this" what do you mean? A grid of NxM rasters with polygon overlays and a single legend on one side? – Spacedman Jan 26 '16 at 10:17
  • I think you maybe trying to merge these objects(?) or convert the grid to polygons(?) when all you want is to plot. Does this work? image(SGDF); plot(SPDF, add = TRUE); Otherwise as Spacedman says, please just show us the code – mdsumner Jan 26 '16 at 11:29
  • I edited my post with a example of my routine. I appeciate your help! Thanks!!! – Camilo Andres Jan 26 '16 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.