Skip to content

?Plotting line segments of shapefile in different color

2 messages · Alexander.Herr at csiro.au, Roger Bivand

#
Hi List,

I am unsuccessfully trying to plot line segments of a shapefile with
different colors. Does anyone have a working example for segmented
lines?

Thanks
Herry
#
On Wed, 1 Feb 2006 Alexander.Herr at csiro.au wrote:

            
If each line to be coloured is a separate Lines object:

library(maptools)
fn <- system.file("shapes/fylk-val.shp", package="maptools")[1]
xx <- readShapeLines(fn, proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
plot(xx, col="blue") # all one colour
length(slot(xx, "lines")) # 97
plot(xx, col=colorRampPalette(c("green", "blue", "black"))(97))
length(colorRampPalette(c("green", "blue", "black"))(97)) # 97 colours

The col= argument is used if it is the same length as the number of 
lines; if the lengths differ, the first colour value is used for all 
lines.

If the shapes are not organised as separate Lines objects, then they will 
need to be cut up and re-created as such.

Roger