[R-sig-Geo] spRbind for spplot
Jon Olav Skoien
jon.skoien at jrc.ec.europa.eu
Wed Aug 18 14:37:46 CEST 2010
Hi Klaus,
> When I try
>> plot_poly = rtopObj3$observations
>> plot_poly$predictions = rtopObj3$predictions$var1.pred
>> spplot(plot_poly, c("observations", "predictions"))
> it does not work since the replacement has 2100 rows and the data has
> 100.
>
> I would like to create a new object (e.g. plot_poly) which holds the
> spatial information of all catchment-polygons (nor) as well as the
> attributes of both observations$QNORM_12_4 and predictions$var1.pred
> to the corresponding areas. Therefore, I thought spRbind might be a
> propper solution.
Following up on Pauls suggestion, I think the best is first to make sure
that you have the same column names in both objects:
observations$var1.pred = NA
predictions$QNORM_12_4 = NA
obs = observations[,c("QNORM_12_4","var1.pred")]
pred = predictions[,c("QNORM_12_4","var1.pred")]
# Now both objects should just contain columns for observations and
predictions
Then you most likely have to make sure that you have different polygon
IDs in the two objects. You can try without first, but will most likely
get an error. If the following does not work, try a larger number:
pred = spChFIDs(pred,as.character(1000+c(1:dim(pred)[1])))
You can then combine the objects:
plot_poly = spRbind(obs,pred)
spplot(plot_poly,c("QNORM_12_4","var1.pred"))
Hope this works!
Jon
More information about the R-sig-Geo
mailing list