[R] draw points in R

Sarah Goslee sarah.goslee at gmail.com
Wed Sep 14 20:47:15 CEST 2011


Hi,

> The probleme is that when I use points function; it plots to me lines and
> not simpe points.

That seems unlikely, but without your code it's hard to figure out
what you did. As usual, the telepathy is not working.

Regardless, this will create a graph with points:

x <- read.table("clipboard", header=FALSE, as.is=TRUE)
# including data is good; including data with dput() is better

plot(x[,2], x[,3], type="p", xlab="X", ylab="Y", main="Points")

> I read it with R and next I want to draw a point for each line the X is in
> col  2 and y is in col 3
> but, I need that for each value of the first colomn , to have a color. Thus,
> I want to get a draw with 3 colors for values 0 , 0.2 and 0.4

And here's one way to color them:
plot(x[,2], x[,3], col=c("red", "blue", "green")[as.factor(x[,1])],
xlab="X", ylab="Y", main="Colored Points")

You might be interested in ?par especially pch and also in ?legend
as well as in the basic help for ?plot and ?points.

Sarah

On Wed, Sep 14, 2011 at 1:57 PM, Adel ESSAFI <adelessafi at gmail.com> wrote:
> Hello list
> I have this file
>
> 0   121289479 25
> 0   212599129 1
> 0   285254098   21
> 0   444889848   45
> 0   469197123   30
> 0   640007403   82
> 0   718215617 8
> 0   758534043   56
> 0   799706577   4
> 0   814441385   93
> 0   843545059   37
> 0.2   121289479   6
> 0.2   285254098   3
> 0.2   444889848   6
> 0.2   469197123   13
> 0.2   640007403   24
> 0.2   718215617 3
> 0.2   758534043   2
> 0.2   799706577   2
> 0.2   814441385   70
> 0.2   843545059 3
> 0.4   121289479   1
> 0.4   444889848   14
> 0.4   469197123   4
> 0.4   640007403   11
> 0.4   799706577   2
> 0.4   814441385 8
>
>
>

>
> Thank you in advance for any input.
>
>
>



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list