Setup a vector with the shapes and the colors you want that are the
same length as the number of levels in Age:
> x <- read.table('clipboard', header=TRUE)
> x
y x Age
1 30 0.0323 O
2 24 0.0389 Y
3 158 0.0580 Y
4 120 0.0581 O
5 100 0.0471 Y
6 102 0.0615 Y
7 160 0.0546 O> shapes <- c(16,17)
> colors <- c('red', 'green')
> plot(x$x, x$y, pch=shapes[x$Age], col=colors[x$Age])
>
On Thu, Aug 27, 2009 at 7:48 AM, Mcdonald,
Grant<grant.mcdonald08 at imperial.ac.uk> wrote:> dear sir,
>
> my data larger than this example but is of the following format:
>
> y ? ? ? x ? ? ? Age
> 30 ? ? ?0.0323 ?O
> 24 ? ? ?0.0389 ?Y
> 158 ? ? 0.058 ? Y
> 120 ? ? 0.0581 ?O
> 100 ? ? 0.0471 ?Y
> 102 ? ? 0.0615 ?Y
> 160 ? ? 0.0546 ?O
>
> i ma making a scatter plot of y~x and want to specify different coloured
and filled shaped for the points according the the third categorical variable A.
>
> the code i have managed is :
>
> ?plot(y~x,pch=as.numeric(factor(Age)))
>
> and i can chage the col seperatley with
>
> ?plot(y~xt,pch=as.numeric(factor(maleage)))
>
> and have added a legend with:
>
> legend(locator(1), as.character(levels(factor(maleage))),
pch=1:length(levels(factor(maleage))))
>
> However the problem i have is that using this code R selects the shapes or
colours for me? ?could you help as to how i specify a specific shape for each of
the levels in the Age variable?
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?