Hi, I have a file of the following type: id a b 1 0.5 5 2 0.7 15 3 1.6 7 4 0.5 25 .................... I would like to plot the data in column a on the y-axis and the corresponding data in column id on the x-axis, so plot(a~id). However I would like to colour these points according to the data in column b. column b data may be colour coded into the following bins: 0-9; 10-19; 20-29. Any idea on how to accomplish this? TIA, Anjan -- ==================================anjan purkayastha, phd. research associate fas center for systems biology, harvard university 52 oxford street cambridge ma 02138 phone-703.740.6939 ================================== [[alternative HTML version deleted]]
Hi Anjan,
Try something along the lines of
d$bb <- with(d, cut(b, c(0,9,19,29)))
with(d, plot(a, id, col = bb, pch = 16, las = 1))
legend('topright', as.character(levels(d$bb)), col =
1:length(levels(d$bb)),
ncol = 3, pch = 16)
where 'd' is your original data.frame.
HTH,
Jorge
On Wed, Jan 5, 2011 at 2:00 PM, ANJAN PURKAYASTHA <> wrote:
> Hi,
> I have a file of the following type:
>
> id a b
> 1 0.5 5
> 2 0.7 15
> 3 1.6 7
> 4 0.5 25
> ....................
>
> I would like to plot the data in column a on the y-axis and the
> corresponding data in column id on the x-axis, so plot(a~id). However I
> would like to colour these points according to the data in column b.
> column b data may be colour coded into the following bins: 0-9; 10-19;
> 20-29.
> Any idea on how to accomplish this?
> TIA,
> Anjan
>
> --
> ==================================> anjan purkayastha, phd.
> research associate
> fas center for systems biology,
> harvard university
> 52 oxford street
> cambridge ma 02138
> phone-703.740.6939
> ==================================>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
On Jan 5, 2011, at 2:00 PM, ANJAN PURKAYASTHA wrote:> Hi, > I have a file of the following type: > > id a b > 1 0.5 5 > 2 0.7 15 > 3 1.6 7 > 4 0.5 25 > .................... > > I would like to plot the data in column a on the y-axis and the > corresponding data in column id on the x-axis, so plot(a~id). > However I > would like to colour these points according to the data in column b. > column b data may be colour coded into the following bins: 0-9; 10-19; > 20-29. > Any idea on how to accomplish this?Something along the lines of this code: plot(a ~ id, data=dfrm, col=c("red", "green", "blue")[findInterval(dfrm$b, c(0,10,20,30) )] ) -- David.> TIA, > Anjan > > -- > ==================================> anjan purkayastha, phd. > research associate > fas center for systems biology, > harvard university > 52 oxford street > cambridge ma 02138 > phone-703.740.6939 > ==================================> > [[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.David Winsemius, MD West Hartford, CT
With xx as your data.frame library(ggplot2) qplot(a, id, data=xx, color=b) --- On Wed, 1/5/11, ANJAN PURKAYASTHA <anjan.purkayastha at gmail.com> wrote:> From: ANJAN PURKAYASTHA <anjan.purkayastha at gmail.com> > Subject: [R] Plotting colour-coded points > To: r-help at r-project.org > Received: Wednesday, January 5, 2011, 2:00 PM > Hi, > I have a file of the following type: > > id? ? a? ? ? ? b > 1???0.5? ? ???5 > 2???0.7? ? ? 15 > 3???1.6? ? ???7 > 4? ? 0.5? ???25 > .................... > > I would like to plot the data in column a on the y-axis and > the > corresponding data in column id on the x-axis, so > plot(a~id).? However I > would like to colour these points according to the data in > column b. > column b data may be colour coded into the following bins: > 0-9; 10-19; > 20-29. > Any idea on how to accomplish this? > TIA, > Anjan > > -- > ==================================> anjan purkayastha, phd. > research associate > fas center for systems biology, > harvard university > 52 oxford street > cambridge ma 02138 > phone-703.740.6939 > ==================================> > ??? [[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. >