0

I have been onto this all day but haven't found a satisfying solution yet. I plotted a raster and created a matrix (="coord_mat"; left column contains X-coordinates, right column the Y-coordinates) that contains the coordinates of multiple points within that raster. Now i want to connect all those points with a line (without plotting the points too) and plot that line in the raster I already plotted. My code so far is the following:

for(k in 1:nrow(coord_mat))
      {
      x <- coord_mat[k,1]
      y <- coord_mat[k,2]
      lines(x,y)
      }

I'm pretty much a newbie in R so I will be thankful for any hint. Thanks in advance :)

snoops
  • 37
  • 7
  • you need a reproducible example. Without data, we can't test your code. – MLavoie Apr 09 '16 at 18:13
  • 1
    Why wouldn't this just be: `lines( coord_mat[,1], coord_mat[,2])`? Unless, of course, you are using a plot-function that is not base-graphics and have failed to advise us by posting code. – IRTFM Apr 09 '16 at 23:02
  • as @42- said, `lines( coord_mat[,1], coord_mat[,2])` should do the trick – maRtin Apr 10 '16 at 01:02
  • Yes it worked, thanks a lot. Does anybody know why it didn't work the way i tried it ? I did basically the same with the only difference that I saved the coordinates into an object before plotting them, didn't I ? – snoops Apr 10 '16 at 10:32
  • Anyway, thanks again ! – snoops Apr 10 '16 at 10:33

0 Answers0