On Aug 27, 2010, at 9:09 AM, arvin mer wrote:

Hello to all,I have a data file as

This came to the list mangled because of your failure to follow Posting Guide advice to use plain text. POST IN PLAIN TEXT.


> dput(temp)
structure(list(Class = structure(c(1L, 1L, 2L, 3L, 3L, 2L), .Label = c("A",
"B", "C"), class = "factor"), V1 = c(-2, 0.9, 0.1, 4.1, 1, 1.1
), V2 = c(0, 0.7, 0.6, 0.4, 1.9, 0.5)), .Names = c("Class", "V1",
"V2"), class = "data.frame", row.names = c(NA, -6L))

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

It would seem superfluous to plot with a character and then also label it with characters. so see if this gets you any further. Note: I did not attach() your dataframe, but rather used with():

with(temp, plot(V1 ,V2, col=c("red", "green", "blue") [as.numeric(Class)])) ?plot # tells me that one cannot use a vector of characters for plotting symbols
 with(temp, text(x=V1, y=V2, labels=Class, pos=4))

# If you wanted to plot as characters you could use text after plotting blanks I suppose.

with(temp, text(x=V1, y=V2, labels=Class, col=c("red", "green", "blue") [as.numeric(Class)]))

Regards
Arvind



David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to