[R] Adding polygons to a barplot

Marc Schwartz (via MN) mschwartz at mn.rr.com
Wed Mar 8 22:46:25 CET 2006


On Wed, 2006-03-08 at 14:02 -0500, Jamieson Cobleigh wrote:
> I have a barplot I have created using barplot2 and I have been able to
> add points and lines (using the points and lines methods,
> respectively).  I now need to add some polygons (triangles in
> particular), that I want to be shaded to match bars in the plot.  I
> can get the coordinates of the corners of the triangles, but don't
> know how to draw the triangles.  I know there is the grid.polygon
> method, but I don't know how to get it to draw on my plot.  Any help
> would be appreciated.
> 
> Thanks!
> 
> Jamie

There is a polygon() function in base R graphics. It supports a
'density' argument in the same fashion as barplot()/barplot2().

See ?polygon

help.search("polygon") would have gotten you there.

HTH,

Marc Schwartz




More information about the R-help mailing list