0

In a SpatialDataFrame I have the following structure for the data.

> str(shapedata_trans@data)
'data.frame':   4066 obs. of  6 variables:
 $ OBJECTID  : num  1 2 3 4 5 6 7 8 9 10 ...
 $ PC4       : Factor w/ 4066 levels "1011","1012",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ Aantal_mul: Factor w/ 11 levels "1","10","12",..: 1 1 5 7 1 1 5 1 1 1 ...
 $ Aantal_adr: Factor w/ 2653 levels "1","10","100",..: 2404 2599 320 383 97 2604 60 211 63 1450 ...
 $ Shape_Leng: num  5908 5489 19421 15356 4733 ...
 $ Shape_Area: num  1034025 1214502 5075544 2674418 770406 ...

And in addition to that it has more information about the polygons and their coordinates... Which is great. However, in order to reduce this to a simple table we can use ggplo2::fortify or broom::tidy

> fort_PC = fortify(shapedata_trans)
> head(fort_PC)
      long      lat order  hole piece group id
1 4.906544 52.37910     1 FALSE     1   0.1  0
2 4.906733 52.37906     2 FALSE     1   0.1  0
3 4.906739 52.37908     3 FALSE     1   0.1  0
4 4.907138 52.37901     4 FALSE     1   0.1  0
5 4.908692 52.37881     5 FALSE     1   0.1  0
6 4.909105 52.37875     6 FALSE     1   0.1  0

However I want to add the information in the @data part to this final table.. Information like the columns PC4, Aantal_mul, Aantal_adr, Shape_Area and Shape_Leng. I know that in fortify/tidy I can specify the region by saying

> head(fortify(shapedata_trans,region = c("PC4")))
      long      lat order  hole piece   id  group
1 4.906544 52.37910     1 FALSE     1 1011 1011.1
2 4.906733 52.37906     2 FALSE     1 1011 1011.1
3 4.906739 52.37908     3 FALSE     1 1011 1011.1
4 4.907138 52.37901     4 FALSE     1 1011 1011.1
5 4.908692 52.37881     5 FALSE     1 1011 1011.1
6 4.909105 52.37875     6 FALSE     1 1011 1011.1

But this doesnt make it better. Does anyone have a solution?

zwep
  • 1,207
  • 12
  • 26

1 Answers1

0

Thanks to Chinsoon12

merge(fortify(shapedata_trans), shapedata_trans@data, by.x="id", by.y="OBJECTID", all=TRUE)

Thanks again!

zwep
  • 1,207
  • 12
  • 26