[R] lines()
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Nov 23 22:00:05 CET 2012
On 23/11/2012 11:56 AM, wdmc2012 wrote:
> I have some latitude and longitudes that I am trying to plot on an image with the lines() command like this:
>
> image(seq(-98, -93, 0.1), seq(28.5, 32.5, 0.1), z, xlab= "Longitude", ylab= "Latitude", main= "Temperature")
> for (i in 2:length(subset(geo, Feature=="Coast")[,1])) {
> lines(x=geo[(i-1),2]:geo[i,2], y=geo[(i-1),1]:geo[i,1], col="blue", lwd=3) }
The expression
x=geo[(i-1),2]:geo[i,2]
probably isn't what you intended. It is the sequence of values from
geo[(i-1),2] to geo[i,2], taking integer steps. E.g. 1.2:1.8
just gives the single value 1.2; 1.2:3.4 gives the sequence 1.2, 2.2, 3.2.
I would guess you wanted
x=c(geo[(i-1),2], geo[i,2])
instead; it's the pair of points.
I think there's another error here too; you let i range over the rows of a subset of geo, but then plot values from the original matrix/dataframe.
Duncan Murdoch
>
> There aren't any errors, but nothing shows up on the plot. I tried substituting "points" for "lines" and all the points came up exactly where they need to be, but how can I make it work with "lines"?
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list