[R-sig-Geo] plot polygons - transparent holes/island

Roger Bivand Roger.Bivand at nhh.no
Tue Feb 2 16:33:50 CET 2010


On Tue, 2 Feb 2010, Paulo Eduardo Cardoso wrote:

> Hi,
>
> A good work around for representation but not exactly what was
> expected for the real dataset.
>
> The image with alpha channel (transparency) is just a schema to
> provide the idea of hidden points but they are not supposed to be
> visible. Sorry.
>
> Considering that all points are plotted at first, wihout using
> "in-out", is there a way to overlap areas[1,] keeping "in" points
> visible?

No, because the enclosing square overpaints them, and the hole is painted 
on top of that - that is the graphics model. The only way round would be 
(as old plotter-based representations) to make returning lines in to the 
hole and back out to the perimeter, so that the hole would be "outside" 
the square. This has been dropped everywhere because of the difficulty of 
hiding the "moorings". If you want to show the points in the hole in 
areas[1,], you have to paint areas[1,] first, then the points in the hole.

In general terms:

plot(areas[1,], pbg="white", col="grey85", border="grey50")
o <- overlay(pontos, areas[1,])
points(pontos[is.na(o),], pch=16)

shows the points in the hole, but you can't use a polygon with an 
un-"moored" hole as a mask.

Roger

>
> Paulo
>
>
> 2010/2/2 Roger Bivand <Roger.Bivand at nhh.no>:
>> On Mon, 1 Feb 2010, Paulo Eduardo Cardoso wrote:
>>
>>> Hi,
>>> Code exemple
>>> library(maptools)
>>> load(file='D:\\R\\transparencia\\TransparentPolygon.Rdata')
>>> areas <- readShapeSpatial('D:\\R\\transparencia\\Areas.shp')
>>> pontos <- readShapeSpatial('D:\\R\\transparencia\\Points.shp')
>>> plot(pontos,pch=19,col=pontos$point)
>>> plot(areas,pbg="transparent",bg="red",add=TRUE)
>>>
>>> data can be downloaded from
>>>
>>> http://rapidshare.com/files/344532718/TransparentPolygon.Rdata.html
>>>
>>> example image can be downloaded grom
>>>
>>> http://rapidshare.com/files/344533300/ExampleTransparentPolygon.png.html
>>>
>>
>> The image cannot be reproduced with your plotting order, because the
>> polygons overpaint the points. Crucially, the big square is completely
>> painted. You also have two Polygons objects, one a square with a round hole,
>> the other an island filling the hole. With your objects, you could do:
>>
>> plot(areas[1,], pbg="white", col="grey85", border="grey50") # set up
>> background polygon and paint hole
>> plot(areas[2,], angle=45, density=8, border="grey50", col="grey50",
>>  add=TRUE)
>> # hatch the island polygon
>> points(pontos[pontos$point=="in",], pch=16)
>> # add the in points
>> points(pontos[pontos$point=="out",], pch=22, col="grey50", bg="grey50")
>> # and the out points
>>
>> If your output devive uses and alpha channel, you may be able to find other
>> ways forward, but they will not be portable across devices.
>>
>> Hope this helps,
>>
>> Roger
>>
>>>
>>>
>>>
>>>
>>> 2010/1/31 Roger Bivand <Roger.Bivand at nhh.no>
>>>>
>>>> On Sun, 31 Jan 2010, Paulo Eduardo Cardoso wrote:
>>>>
>>>>> Roger,
>>>>>
>>>>> I really thank you for you comments. You are always available to explain
>>>>> everything, and that's a fortune for forum users.
>>>>> But I still with the same problem. I did,'t understand how to leave the
>>>>> inner hole or the inner polygon transparent, in order to see any other
>>>>> layer
>>>>> plotter at first.
>>>>> Should I send a simple example?
>>>>
>>>> Please do, either code for a provided data set, or code and a link to the
>>>> URL where the data set is available.
>>>>
>>>> Roger
>>>>
>>>>>
>>>>> 2010/1/30 Roger Bivand <Roger.Bivand at nhh.no>
>>>>>
>>>>>> On Sat, 30 Jan 2010, Paulo Eduardo Cardoso wrote:
>>>>>>
>>>>>>  I'd like to plot a SPDF with two objects, one of them buffering the
>>>>>> other
>>>>>>>
>>>>>>> "island". How can I set the "island" transparent?
>>>>>>> Similarly, keeping the outer polygon only, how can the hole still
>>>>>>> transparent?
>>>>>>>
>>>>>>
>>>>>> Polygons objects are plotted largest to smallest, as are Polygon
>>>>>> objects in
>>>>>> each Polygons object. Each Polygons object and all its constituent
>>>>>> Polygon
>>>>>> objects are painted the colour chosen for that Polygons object.
>>>>>>
>>>>>> If you want the holes Polygon objects to overpaint their containing
>>>>>> Polygon
>>>>>> objects, in the base graphics plot() method, you set the pbg= argument
>>>>>> to
>>>>>> the background colour (not "transparent", this will let you see the
>>>>>> painted
>>>>>> Polygon below). In the spplot method, this is handled internally by
>>>>>> reading
>>>>>> the trellis.par.get()$background value, and using it if not
>>>>>> "transparent",
>>>>>> or "white" if it is "transparent".
>>>>>>
>>>>>> Both approaches depend on the hole slot of the Polygon object being
>>>>>> correctly set.
>>>>>>
>>>>>> R graphics do not analyse objects leaving out say holes, they
>>>>>> overpaint.
>>>>>> This is because the holes are not "known" in advance by the functions
>>>>>> being
>>>>>> executed.
>>>>>>
>>>>>> Hope this helps,
>>>>>>
>>>>>> Roger
>>>>>>
>>>>>>
>>>>>>> Thanks in advance,
>>>>>>>
>>>>>>> Paulo E. Cardoso
>>>>>>>
>>>>>>>       [[alternative HTML version deleted]]
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> 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
>>>>
>>>
>>
>> --
>> 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
>>
>

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