[R] plot data by class tag

Joshua Wiley jwiley.psych at gmail.com
Fri Aug 27 15:56:39 CEST 2010


Hi,

This should do it.  I let plot() choose whatever colors it wanted, but
if you really wanted you could set them manually.  Many thanks to
David for the data.

plot(temp$V1, temp$V2, pch = as.character(temp$Class), col = temp$Class)


# As an alternative using ggplot2
# I do not use "A", "B", "C", but there are different shapes and there
is a nice legend

library(ggplot2)
qplot(x = V1, y = V2, colour = Class, shape = Class, data = temp, geom
= "point")

HTH,

Josh


On Fri, Aug 27, 2010 at 6:09 AM, arvin mer <arvindmer at yahoo.com> wrote:
> Hello to all,I have a data file as
> Class V1        V2A     -2.0    0.0A     0.9    0.7B     0.1    0.6C     4.1    0.4C     1.0    1.9B     1.1    0.5
> I am plotting this data in R as V1 verses V2> temp<-read.table('temp.dat', header=T)> attach(temp)> plot (V1,V2, col='red')> text(x=V1, y=V2, labels=Class, pos=4)
> But I want to change the  'plotting symbol'  by the 'Class of  the row' (which is A,B,C).in other words "I want to use the A,B,C instead of red circle and want different color for each class e.g. Red for 'A', Green for 'B'  and so on"
> How to do that ??Thanks in advance
> Regards
> Arvind
>
>
>
>
>        [[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.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list