[R] Help in plotting

David Winsemius dwinsemius at comcast.net
Sun Jul 31 19:29:23 CEST 2016


> On Jul 31, 2016, at 8:07 AM, Bhaskar Mitra <bhaskar.kolkata at gmail.com> wrote:
> 
> 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.

> 	[[alternative HTML version deleted]]

And I suggest you read the Posting Guide more carefully.

> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list