[R-sig-Geo] ?Plotting line segments of shapefile in different color

Roger Bivand Roger.Bivand at nhh.no
Wed Feb 1 08:36:25 CET 2006


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

> 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?

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


> 
> Thanks
> Herry
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list