[R] Plotting lines with shapes

Marc Schwartz MSchwartz at mn.rr.com
Tue Jun 21 00:42:34 CEST 2005


On Mon, 2005-06-20 at 16:44 -0400, Hikel, Jerry wrote:
> I am currently attempting to work on some graphs whose plotted lines
> have simple polygons at regular intervals, such as a triangle or a
> square.
> 
> I haven't been able to find anything in the base R plotting packages, or
> in any extensions that would allow me to do this easily. I am familiar
> with polygon drawing and shading, but i was wondering if anyone knew of
> any packages that have these types of graphing capabilities built in to
> the line functions themselves. Thanks.


There are multiple approaches here, but using the base graphics package:

# plot type = 'b' uses both lines and symbols
plot(10:30, type = "b", pch = 24, bg = "black")

plot(10:30, type = "b", pch = 22, cex = 1.5)



You also have the option of doing them separately, which may give you
more control in some situations:

1. Draw the line(s) first and then add the symbols:

 plot(10:30, type = "l")
 points(10:30, pch = 22, bg = "black")


2. Draw the symbols and then add the line(s):

 plot(10:30, pch = 24, bg = "black") 
 lines(10:30)


See ?plot.default, ?lines and ?points for more information on plots and
symbols. Note the 'cex' and 'bg' arguments, which enable you to adjust
the size of the symbols and the fill color for the symbols.

HTH,

Marc Schwartz




More information about the R-help mailing list