1

How can I merge two plots (layers)? On a first plot there are points with data, and on the second one there is a boundary of those points. Here is what i've got:

data <- read.csv('data.csv')
coordinates(data) <- ~x+y 
proj4string(data) <- '+init=epsg:2180' 
plot(data)
boundary <- readOGR(dsn='.', layer='boundary')
plot(boundary)

The thing is, that I want to merge boundary with data. I also want to change a colour of boundary. Thank you in advance.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Hubert
  • 51
  • 9
  • Setting `add = TRUE` inside `plot` usually works, though it will depend on exactly what plotting method is being called (maybe `plot.SpatialPointsDataFrame` in this case?). Other options are to use `lines()` or `points()` instead of `plot`. – Gregor Thomas Dec 27 '16 at 17:25
  • 1
    Also, please don't use RStudio or the RStudio tag unless the question is specific to the code editor RStudio. Your issue appears to be an R issue, and it doesn't matter if you are writing your R code in RStudio, emacs, Vi, notepad, Word, or on your whiteboard. – Gregor Thomas Dec 27 '16 at 17:26
  • Please, include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) when asking. In particular, your code snippet is lacking information on which libraries are required. This will help to avoid confusion for those who are willing to spent their time on helping you. – Uwe Dec 27 '16 at 21:01

1 Answers1

0

What you want might be polygon

#Example Data
set.seed(42)
mydata = cbind(rnorm(100),rnorm(100))
boundary = mydata[chull(mydata),]

#Plot points first
plot(mydata,xlab="X-axis",ylab="Y-axis")
#Then plot the boundary
polygon(boundary,lty = 2)
d.b
  • 32,245
  • 6
  • 36
  • 77