Skip to content

Help in plotting

2 messages · Bhaskar Mitra, David Winsemius

#
Hello Everyone,


I have a data frame with 2 columns as shown at the end of this mail. I want
to plot the data in column A;
 however I want the  data-points in column A to be of different color based
on conditions in column B.
i.e all data in column A corresponding to value 0 in column B should be
red.
Similarly all values in column A corresponding to value 2 in column B
should be green.

Any suggestions or help in this regard.

Best,
Bhaskar





A       B
12      0
11      1
23      2
34      0
45      1
67      3
?         ..
#
This should do it:

plot(1:length(dfrm$A), dfrm$A, col = c("red", "blue", "green") [ 1+dfrm$B] )

I suggest reading more at: 

?palette   # ..... and follow the links to other relevant help pages.
And I suggest you read the Posting Guide more carefully.
David Winsemius
Alameda, CA, USA