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

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Feb 11 22:23:37 CET 2020

```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:

-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",
# 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:
>
>      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:
> >
> >                    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.
> >