[R] how to create density plot in R with p value

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Tue Feb 11 22:55:56 CET 2020


Hi Jim


I tried your code and it didn't show me density curves.

However I was able to do teh plot myself via:

densityplot(~dat,data=tot,
       groups=type,
       par.settings = list(superpose.line = list(col = c("blue","red"))),
       xlab="log2 (variance)",
       plot.points=FALSE,
       auto.key=TRUE)


and it is attached. The only thing I need to do is to make a line in
between peaks of the curves and put the star above that line. Not a p
value but just a star symbol.

Please advise,
Thanks

On Tue, Feb 11, 2020 at 3:46 PM Ana Marija <sokovic.anamarija using gmail.com> wrote:
>
> Hi Jim
>
>
> I tried your code and it didn't show me density curves.
>
> However I was able to do teh plot myself via:
>
> densityplot(~dat,data=tot,
>        groups=type,
>        par.settings = list(superpose.line = list(col = c("blue","red"))),
>        xlab="log2 (variance)",
>        plot.points=FALSE,
>        auto.key=TRUE)
>
>
> and it is attached. The only thing I need to do is to make a line in
> between peaks of the curves and put the star above that line. Not a p
> value but just a star symbol.
>
> Please advise,
> Thanks
> Ana
>
> On Tue, Feb 11, 2020 at 3:23 PM Jim Lemon <drjimlemon using gmail.com> wrote:
> >
> > Hi Ana,
> > Your image didn't make it through (as usual). Try PNG or PDF format.
> >
> > Assumptions
> > 1) You want to plot two lines using the _paired_ values of inter- and
> > intra-individual variance.
> > 2) The cases are in the same order in your data
> > 3) You want to identify the two lines
> > 4) You want to place text with some p-value between the lines
> >
> > This is really (and suspiciously) simple. Here's a start:
> >
> > tot<-read.table(text="dat type
> >  -3.962 inter.individual.variance
> >  -4.301 inter.individual.variance
> >  -1.690 inter.individual.variance
> >  -0.375 inter.individual.variance
> >   1.816 inter.individual.variance
> >   0.138 inter.individual.variance
> >  -4.09 intra.individual.variance
> >  -4.64 intra.individual.variance
> >  -5.57 intra.individual.variance
> >  -2.96 intra.individual.variance
> >  -4.43 intra.individual.variance
> >  -3.60 intra.individual.variance",
> >  header=TRUE)
> > # get the numeric values of the factor 'type'
> > tot$ntype<-as.numeric(tot$type)
> > plot(tot$dat[tot$ntype==1],type="l",col="green",ylim=range(tot$dat))
> > lines(tot$dat[tot$ntype==2],col="blue")
> > text(5,-1.5,"p = 0.005")
> > legend(1,1,c("Inter-individual variance","Intra-individual variance"),
> >  lty=1,col=c("green","blue"))
> >
> > Jim
> >
> > On Wed, Feb 12, 2020 at 7:07 AM Ana Marija <sokovic.anamarija using gmail.com> wrote:
> > >
> > > so I transformed my data from the previous email to look like this:
> > >
> > > > head(tot)
> > >      dat                      type
> > > 1 -3.962 inter.individual.variance
> > > 2 -4.301 inter.individual.variance
> > > 3 -1.690 inter.individual.variance
> > > 4 -0.375 inter.individual.variance
> > > 5  1.816 inter.individual.variance
> > > 6  0.138 inter.individual.variance
> > > > tail(tot)
> > >         dat                      type
> > > 31177 -4.09 intra.individual.variance
> > > 31178 -4.64 intra.individual.variance
> > > 31179 -5.57 intra.individual.variance
> > > 31180 -2.96 intra.individual.variance
> > > 31181 -4.43 intra.individual.variance
> > > 31182 -3.60 intra.individual.variance
> > >
> > > then I can make plot using this:
> > >
> > > densityplot(~dat,data=tot,
> > >        groups=type,
> > >        par.settings = list(superpose.line = list(col = c("blue","red"))),
> > >        xlab="log2 (variance)",
> > >        plot.points=FALSE,
> > >        auto.key=TRUE)
> > >
> > > and calculate my p value with t test, say it is 0.005
> > >
> > > But how to add that p value in between distribution of the curves?
> > >
> > > Thanks
> > > Ana
> > >
> > > On Tue, Feb 11, 2020 at 12:54 PM Ana Marija <sokovic.anamarija using gmail.com> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I have data like this:
> > > >
> > > > > head(a)
> > > >                    X   geneID inter.individual.variance
> > > > intra.individual.variance F.value  p.value     CV
> > > > 1 3iUZ.47hLFki49VR4o   MLLT10                    0.0642
> > > >    0.01395    4.60 1.00e-05 0.0222
> > > > 2 fEn1QlU0MCVe9GeR64 C1orf123                    0.0507
> > > >    0.00671    7.57 1.00e-08 0.0172
> > > > 3 ud_tTlU5LtB478JxIk    FSD1L                    0.3100
> > > >    0.02682   11.56 1.00e-11 0.0639
> > > > 4 3KV3OJIIRuJ5KJ6VkI  TXNDC11                    0.7710
> > > >    0.02813   27.41 9.99e-19 0.0688
> > > > 5 o_rupcEAKnQqnoh6ec   CYB5R2                    3.5209
> > > >    0.03391  103.83 9.99e-31 0.1357
> > > > 6 Nk_t6ULcQ7VDNChBRU     GBP1                    1.1005
> > > >    0.09522   11.56 9.98e-12 0.0773
> > > >
> > > > I would like to create density plot, like the attached between
> > > > "inter.individual.variance" and "intra.individual.variance" and have p
> > > > value between those two curves.
> > > >
> > > > Please advise,
> > > > Ana
> > >
> > > ______________________________________________
> > > R-help using 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rsz_newp.png
Type: image/png
Size: 51078 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200211/ce686146/attachment.png>


More information about the R-help mailing list