[R] Filled vector contours

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Aug 24 12:19:38 CEST 2014


On 24/08/2014 08:51, Jan Tosovsky wrote:
> Dear All,
>
> I am trying to create vector output (SVG) of filled contours.
>
> I've found two approaches so far:
>
> (1)
> library('lattice')
> svg("D:/test.svg")
> filled.contour(volcano)
> #levelplot(volcano, panel=panel.levelplot.raster) # panel.levelplot.raster
> will make it raster
> dev.off()
>
> (2)
> library("raster")
> svg("D:/test.svg")
> rr <- raster(t(volcano))
> rc <- cut(rr, breaks= 10)
> pols <- rasterToPolygons(rc, dissolve=T)
> spplot(pols)
> dev.off()
>
> But I'd like to get smooth closed polygons not broken into small cells.

But the region between two contours is not in general a closed polygon.

> Are there better methods in R ?

Neither of those are 'in R'!

So you need to define your terms, precisely.  How can a polygon (with 
piecewise linear boundaries) be 'smooth'?

But you could get a long way by looking at the following

?contourLines
?polygon
?grid::grid.polygon

all of which are part of R.  R is a fully-fledged programming language 
and you could write SVG directly from R: using the svg device is limited 
by the steps to the R graphics primitives (see the 'R Internals' manual) 
and cairographics.

> Thanks, Jan



-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK



More information about the R-help mailing list