[R] how to plot a graph with different pch
Charles C. Berry
cberry at tajo.ucsd.edu
Mon Oct 1 21:43:19 CEST 2007
On Mon, 1 Oct 2007, Letticia Ramlal wrote:
> I am trying to plot a graph but the points on the graph should be
> different symbols and colors. It should represent what is in the legend.
> I tried using the points command but this does not work.
WHAT "does not work" ???
points() puts points on a plot with colors and symbols as you specify
them.
example(points)
illustrates this with several different setups.
It even shows how to construct "red symbols with a yellow interior (where
available)"!!
Read the help page, run and study the example()'s
Is there
> another command in R that would allow me to use different symbols and
> colors for the points?
>
> Thank you kindly.
>
>
>
>
>
> data(mtcars)
>
> plot(mtcars$wt,mtcars$mpg,xlab= "Weight(lbs/1000)", ylab="Miles per
> Gallon")
>
> mtcars$wt.cyl<-mtcars$wt[mtcars$cyl]
>
> mtcars$mpg.cyl<-mtcars$mpg[mtcars$cyl]
>
> points(mtcars$wt.cyl, mtcars$mpg.cyl, pch = 17, col = "red")
>
> title("Motor Trend Data")
>
> text(2,10,"LTR",cex=1.2,adj=0,col=3)
>
> legend(4,30,c("4 cylinder","6 cylinder","8 cylinder"),pch=c(3,17,19),
> cex=1.2, col=c("blue", "red", "purple4"))
>
>
>
>
>
> LTR
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the R-help
mailing list