how to add p values to bar plot?

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

how to add p values to bar plot?

anikaM
Hi,

I have a bar plot (green colors in attach) which I made with this:

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 2nd attached figure (gray and blue)?

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 9.20.50 PM.png (105K) Download Attachment
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?

Jim Lemon-4
Hi Ana,
You seem to have a p-value at the top of the second plot. Do you just
want that p-value in a different place?
My first guess would be the "annotate" argument. Say you wanted your
p-value in the middle of the plot.

# your ggplot line
 p+annotate("text",x=1.5,y=0.05,label="p = 1.6x10-16")
p

Note: untested

Jim

On Sat, Sep 28, 2019 at 6:52 PM Ana Marija <[hidden email]> wrote:

>
> Hi,
>
> I have a bar plot (green colors in attach) which I made with this:
>
> 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 2nd attached figure (gray and blue)?
>
> 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.

______________________________________________
[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.