how to add p values to bar plot?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

how to add p values to bar plot?

anikaM
Hi,

I created a bar plot with this code:

library(ggplot2)
df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG Genes"))
p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
  geom_bar(stat="identity")+ labs(x="", y = "Proportion of cis
EQTLs")+ scale_fill_brewer(palette="Greens") +
theme_minimal()+theme(legend.position = "none")
p

What do I need to change in my plot so that I have plot with p value
shown on the attached figure?

Thanks
Ana

______________________________________________
[hidden email] 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.

Screen Shot 2019-09-27 at 1.30.37 PM.png (142K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: how to add p values to bar plot?

Vivek Das
You will need to add stat_compare_means. Take a look at here.


http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/

library(ggpubr)
p + stat_compare_means()

Should be fine.

Vivek

On Fri, Sep 27, 2019 at 7:29 PM Ana Marija <[hidden email]>
wrote:

> Hi,
>
> I created a bar plot with this code:
>
> library(ggplot2)
> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
> Genes"))
> p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
>   geom_bar(stat="identity")+ labs(x="", y = "Proportion of cis
> EQTLs")+ scale_fill_brewer(palette="Greens") +
> theme_minimal()+theme(legend.position = "none")
> p
>
> What do I need to change in my plot so that I have plot with p value
> shown on the attached figure?
>
> Thanks
> Ana
> ______________________________________________
> [hidden email] 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.
>
--
----------------------------------------------------------

Vivek Das, PhD

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to add p values to bar plot?

Vivek Das
Ah, this is a single observation and not pvalue calculation over a
distribution. You don’t seem to have a spread. Here your code seemed like
it was over all genes(more than 1) vs RG genes(also more than one). But it
is basically an observation of difference of 2 values. So it doesn’t need
to calculate any pvalues. Probability calculation is only needed when you
have distribution of data in each arm to make Ho(null hypothesis) thar
ststes condition 1 vs condition 2 have no difference but when you compute
the distribution, you find a difference that rejects your Null and makes
the alternative hypotheses true.

Just observed your “prop” is between only two values. So no reason for
comparing since there is no distribution.

Just make barplot and compute the Delta that can be difference between
70.42-7.75 or fold change 70.42/7.75. If they are absolute value you can
also scale them in log scale and do the same. Hope this helps. Good luck.

Vivek

On Fri, Sep 27, 2019 at 9:32 PM Ana Marija <[hidden email]>
wrote:

> Hi Vivek,
>
> Thanks for getting back to me and yes that is what I tried:
>
> library(ggpubr)
> library(ggplot2)
> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
> Genes"))
> my_comparisons <- list(c("All Genes","RG Genes"))
>
> p <-ggbarplot(df, x="Name", y="prop",fill="Name",legend ="",color =
> "white",palette = "jco",xlab = FALSE,ylab="cis eqtl per gene")
>
> p + stat_compare_means(comparisons=my_comparisons)
>
> I got p value 1, I am wondering does putting here p value makes sense
> because I don't have any distribution, I just have these two numbers
> on y axis:
> "prop" = c(7.75,70.42)
>
> Please advise,
>
> Thanks
> Ana
>
>
> On Fri, Sep 27, 2019 at 11:21 PM Vivek Das <[hidden email]> wrote:
> >
> > You will need to add stat_compare_means. Take a look at here.
> >
> >
> >
> http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/
> >
> > library(ggpubr)
> > p + stat_compare_means()
> >
> > Should be fine.
> >
> > Vivek
> >
> > On Fri, Sep 27, 2019 at 7:29 PM Ana Marija <[hidden email]>
> wrote:
> >>
> >> Hi,
> >>
> >> I created a bar plot with this code:
> >>
> >> library(ggplot2)
> >> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
> Genes"))
> >> p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
> >>   geom_bar(stat="identity")+ labs(x="", y = "Proportion of cis
> >> EQTLs")+ scale_fill_brewer(palette="Greens") +
> >> theme_minimal()+theme(legend.position = "none")
> >> p
> >>
> >> What do I need to change in my plot so that I have plot with p value
> >> shown on the attached figure?
> >>
> >> Thanks
> >> Ana
> >> ______________________________________________
> >> [hidden email] 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.
> >
> > --
> > ----------------------------------------------------------
> >
> > Vivek Das, PhD
>
--
----------------------------------------------------------

Vivek Das, PhD

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to add p values to bar plot?

anikaM
Awesome, thanks!

Yes those two numbers on y axis I calculated as (#of EQTLs)/(#of genes) and
the same for the other, RG condition. So implicitly I do have a spread just
that data was not used to plot this, only those ratios. Is in this case
still p value not necessary?

On Fri, 27 Sep 2019 at 23:43, Vivek Das <[hidden email]> wrote:

> Ah, this is a single observation and not pvalue calculation over a
> distribution. You don’t seem to have a spread. Here your code seemed like
> it was over all genes(more than 1) vs RG genes(also more than one). But it
> is basically an observation of difference of 2 values. So it doesn’t need
> to calculate any pvalues. Probability calculation is only needed when you
> have distribution of data in each arm to make Ho(null hypothesis) thar
> ststes condition 1 vs condition 2 have no difference but when you compute
> the distribution, you find a difference that rejects your Null and makes
> the alternative hypotheses true.
>
> Just observed your “prop” is between only two values. So no reason for
> comparing since there is no distribution.
>
> Just make barplot and compute the Delta that can be difference between
> 70.42-7.75 or fold change 70.42/7.75. If they are absolute value you can
> also scale them in log scale and do the same. Hope this helps. Good luck.
>
> Vivek
>
> On Fri, Sep 27, 2019 at 9:32 PM Ana Marija <[hidden email]>
> wrote:
>
>> Hi Vivek,
>>
>> Thanks for getting back to me and yes that is what I tried:
>>
>> library(ggpubr)
>> library(ggplot2)
>> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
>> Genes"))
>> my_comparisons <- list(c("All Genes","RG Genes"))
>>
>> p <-ggbarplot(df, x="Name", y="prop",fill="Name",legend ="",color =
>> "white",palette = "jco",xlab = FALSE,ylab="cis eqtl per gene")
>>
>> p + stat_compare_means(comparisons=my_comparisons)
>>
>> I got p value 1, I am wondering does putting here p value makes sense
>> because I don't have any distribution, I just have these two numbers
>> on y axis:
>> "prop" = c(7.75,70.42)
>>
>> Please advise,
>>
>> Thanks
>> Ana
>>
>>
>> On Fri, Sep 27, 2019 at 11:21 PM Vivek Das <[hidden email]> wrote:
>> >
>> > You will need to add stat_compare_means. Take a look at here.
>> >
>> >
>> >
>> http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/
>> >
>> > library(ggpubr)
>> > p + stat_compare_means()
>> >
>> > Should be fine.
>> >
>> > Vivek
>> >
>> > On Fri, Sep 27, 2019 at 7:29 PM Ana Marija <[hidden email]>
>> wrote:
>> >>
>> >> Hi,
>> >>
>> >> I created a bar plot with this code:
>> >>
>> >> library(ggplot2)
>> >> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
>> Genes"))
>> >> p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
>> >>   geom_bar(stat="identity")+ labs(x="", y = "Proportion of cis
>> >> EQTLs")+ scale_fill_brewer(palette="Greens") +
>> >> theme_minimal()+theme(legend.position = "none")
>> >> p
>> >>
>> >> What do I need to change in my plot so that I have plot with p value
>> >> shown on the attached figure?
>> >>
>> >> Thanks
>> >> Ana
>> >> ______________________________________________
>> >> [hidden email] 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.
>> >
>> > --
>> > ----------------------------------------------------------
>> >
>> > Vivek Das, PhD
>>
> --
> ----------------------------------------------------------
>
> Vivek Das, PhD
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to add p values to bar plot?

Vivek Das
Well that means already a ratio. Could you show me how the data frame looks
like? If they are array of values then you compare the distribution of your
ratios like Ratio1 array from “ (#of EQTLs)/(#of genes)” vs Ratio 2 arrays
of the “same for the other, RG condition”.

ratio1 = c(ratio1Value1, ratio1Value2, ..., ratio1ValueN)
ratio2 = c(ratio2Value1, ratio2Value2, ..., ratio2ValueN)

your code can compare distribution, means & pvalue of these and make
whisker plots and also the pvalues. This is a better way if you can make
your dataframe in that manner to compute and make the plots. Hope this is
clear.

Vivek

On Fri, Sep 27, 2019 at 9:52 PM Ana Marija <[hidden email]>
wrote:

> Awesome, thanks!
>
> Yes those two numbers on y axis I calculated as (#of EQTLs)/(#of genes)
> and the same for the other, RG condition. So implicitly I do have a spread
> just that data was not used to plot this, only those ratios. Is in this
> case still p value not necessary?
>
> On Fri, 27 Sep 2019 at 23:43, Vivek Das <[hidden email]> wrote:
>
>> Ah, this is a single observation and not pvalue calculation over a
>> distribution. You don’t seem to have a spread. Here your code seemed like
>> it was over all genes(more than 1) vs RG genes(also more than one). But it
>> is basically an observation of difference of 2 values. So it doesn’t need
>> to calculate any pvalues. Probability calculation is only needed when you
>> have distribution of data in each arm to make Ho(null hypothesis) thar
>> ststes condition 1 vs condition 2 have no difference but when you compute
>> the distribution, you find a difference that rejects your Null and makes
>> the alternative hypotheses true.
>>
>> Just observed your “prop” is between only two values. So no reason for
>> comparing since there is no distribution.
>>
>> Just make barplot and compute the Delta that can be difference between
>> 70.42-7.75 or fold change 70.42/7.75. If they are absolute value you can
>> also scale them in log scale and do the same. Hope this helps. Good luck.
>>
>> Vivek
>>
>> On Fri, Sep 27, 2019 at 9:32 PM Ana Marija <[hidden email]>
>> wrote:
>>
>>> Hi Vivek,
>>>
>>> Thanks for getting back to me and yes that is what I tried:
>>>
>>> library(ggpubr)
>>> library(ggplot2)
>>> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
>>> Genes"))
>>> my_comparisons <- list(c("All Genes","RG Genes"))
>>>
>>> p <-ggbarplot(df, x="Name", y="prop",fill="Name",legend ="",color =
>>> "white",palette = "jco",xlab = FALSE,ylab="cis eqtl per gene")
>>>
>>> p + stat_compare_means(comparisons=my_comparisons)
>>>
>>> I got p value 1, I am wondering does putting here p value makes sense
>>> because I don't have any distribution, I just have these two numbers
>>> on y axis:
>>> "prop" = c(7.75,70.42)
>>>
>>> Please advise,
>>>
>>> Thanks
>>> Ana
>>>
>>>
>>> On Fri, Sep 27, 2019 at 11:21 PM Vivek Das <[hidden email]> wrote:
>>> >
>>> > You will need to add stat_compare_means. Take a look at here.
>>> >
>>> >
>>> >
>>> http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/
>>> >
>>> > library(ggpubr)
>>> > p + stat_compare_means()
>>> >
>>> > Should be fine.
>>> >
>>> > Vivek
>>> >
>>> > On Fri, Sep 27, 2019 at 7:29 PM Ana Marija <
>>> [hidden email]> wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I created a bar plot with this code:
>>> >>
>>> >> library(ggplot2)
>>> >> df <- data.frame("prop" = c(7.75,70.42), "Name" = c("All Genes","RG
>>> Genes"))
>>> >> p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
>>> >>   geom_bar(stat="identity")+ labs(x="", y = "Proportion of cis
>>> >> EQTLs")+ scale_fill_brewer(palette="Greens") +
>>> >> theme_minimal()+theme(legend.position = "none")
>>> >> p
>>> >>
>>> >> What do I need to change in my plot so that I have plot with p value
>>> >> shown on the attached figure?
>>> >>
>>> >> Thanks
>>> >> Ana
>>> >> ______________________________________________
>>> >> [hidden email] 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.
>>> >
>>> > --
>>> > ----------------------------------------------------------
>>> >
>>> > Vivek Das, PhD
>>>
>> --
>> ----------------------------------------------------------
>>
>> Vivek Das, PhD
>>
> --
----------------------------------------------------------

Vivek Das, PhD

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.