Question: Display pairwise p values on barplots in ggplot2
1
gravatar for grant.hovhannisyan
14 months ago by
grant.hovhannisyan1.8k wrote:

Hi All,

I am ploting the data of the table below:

method_yeast_cont   n_reads.mean    n_reads.sd  uniq_maps.mean  uniq_maps.sd    uniq_maps_pr.mean   uniq_maps_pr.sd n_reads_multimaps.mean  n_reads_multimaps.sd    n_reads_mult_pr.mean    n_reads_mult_pr.sd  n_reads_unmap_pr.mean   n_reads_unmap_pr.sd calb_uniq_genic.mean    calb_uniq_genic.sd  human_uniq_genic.mean   human_uniq_genic.sd calb_uniq_genic_pr.mean calb_uniq_genic_pr.sd   human_uniq_genic_pr.mean    human_uniq_genic_pr.sd  calb_mapped.mean    calb_mapped.sd  human_mapped.mean   human_mapped.sd calb_mapped_pr.mean calb_mapped_pr.sd   human_mapped_pr.mean    human_mapped_pr.sd  yeast_count probes  method
B_high  26341985.3333333    3475105.53992268    24508638    3199367.16956166    93.0466666667   0.1418919777    879108  125204.982293038    3.3333333333    0.0763762616    3.52    0.0953939201    16698971.3333333    2235797.80039706    6558838.33333333    1741953.44239229    71.8833333333   6.023340712 28.1166666667   6.023340712 35065755.6666667    4664342.44783521    14210982.3333333    3727378.58714839    71.2666666667   5.8559058508    28.7333333333   5.8559058508    Yeast_cells_10e5    No_probes   B
B_low   37380099.6666667    15378674.8120259    33740305.3333333    14518818.6334255    89.8466666667   1.9050021872    1338156.33333333    552088.251294422    3.57    0.1539480432    6.37    1.8256779563    897864.666666667    596329.501304718    30292432.3333333    13244077.2183101    2.6466666667    0.9335059364    97.3533333333   0.9335059364    1895832 1267041.17576186    66659057    28187587.9467176    2.5366666667    0.9200181158    97.4633333333   0.9200181158    Yeast_cells_10e3    No_probes   B
B_probes_high   22835465.6666667    19063360.9909413    21651360    18058227.8410397    94.9    0.2253885534    656112.666666667    556366.1002131  2.8366666667    0.0757187779    2.05    0.1352774926    21072521.6666667    17582520.1738307    132678.666666667    114970.502374885    99.4    0.07    0.6 0.07    43186587.6666667    36022406.5327966    292594  255632.518455693    99.36   0.0781024968    0.64    0.0781024968    Yeast_cells_10e5    With_probes B
B_probes_low    272508.666666667    223662.947468581    251544.666666667    206341.883800486    92.3233333333   1.3355273615    9853.6666666667 8254.8912974874 3.5866666667    0.2706165799    4.0433333333    1.0500634901    187037.333333333    161930.075329858    56122.3333333333    39360.6671733767    75.07   8.0169882125    24.93   8.0169882125    383258  331706.685256719    126556  90020.3188619103    73.3666666667   8.6185923058    26.6333333333   8.6185923058    Yeast_cells_10e3    With_probes B
BT_high 28589201.6666667    2283634.24181924    25503621.6666667    2372981.34012413    89.21   4.0823522631    995669.333333333    87340.9107596969    3.4833333333    0.2013289183    7.2166666667    4.2596869995    14585398    1570767.30154788    9591113.33333333    1868351.79429259    60.44   5.415487051 39.56   5.415487051 30670358.6666667    3108882.03357   20636613    3967057.00806895    59.9    5.5614027008    40.1    5.5614027008    Yeast_cells_10e5    No_probes   BT
BT_low  26687944.3333333    711914.990235023    22349802.3333333    1049397.95223801    83.8233333333   5.3924236975    880367  23453.8112681074    3.3 0.12489996  12.74   5.4193265264    2303765.66666667    1112091.36374775    18930130.3333333    206939.821374073    10.7    4.6779162028    89.3    4.6779162028    4865526 2370856.66483067    40309494.6666667    518543.627620023    10.63   4.730190271 89.37   4.730190271 Yeast_cells_10e3    No_probes   BT
BT_probes_high  9037105.33333333    1263298.71383309    8545261.66666667    1241388.08450111    94.5066666667   0.5852634734    277220  42112.3897089681    3.0633333333    0.0404145188    2.3466666667    0.6285167725    8306823.33333333    1224106.0894981 61651.6666666667    14003.5392074052    99.26   0.1417744688    0.74    0.1417744688    17010048    2475404.34286037    134458.666666667    29720.4710819552    99.2066666667   0.1594783162    0.7933333333    0.1594783162    Yeast_cells_10e5    With_probes BT
BT_probes_low   1283419.33333333    852838.556911174    1208315.66666667    817367.422481673    93.5566666667   1.5392963761    37688   22533.7481791201    3.0333333333    0.2302896727    3.38    1.3018448448    1107799.66666667    780969.798772227    73475.6666666667    18541.9521446188    92.4533333333   3.08138497  7.5466666667    3.08138497  2267740.33333333    1598651.97409453    158999.333333333    38226.3873434743    92.02   3.3482383428    7.98    3.3482383428    Yeast_cells_10e3    With_probes BT
N_high  45394850.6666667    4302853.80510764    41756755    3712627.57294359    92.0233333333   0.833446659 1553274.66666667    167282.705024558    3.42    0.08    4.4966666667    0.763042157 28565666    4467051.95734637    11165194    1000997.87753821    71.6066666667   5.1161052895    28.3933333333   5.1161052895    59620644.6666667    9357026.4782253 24268208.3333333    2115591.94347406    70.78   5.1574509208    29.22   5.1574509208    Yeast_cells_10e5    No_probes   N
N_low   50897109    27145209.3046033    45903568.6666667    24305873.4571379    90.3166666667   0.5918051481    1711402 997816.321238032    3.3066666667    0.1582192572    6.22    0.531130869 2149133.33333333    1194673.19854106    40176542.6666667    21571892.7523443    5.0533333333    0.2214347157    94.9466666667   0.2214347157    4468939.33333333    2462207.88180392    88283124.3333333    46812269.2956677    4.79    0.12489996  95.21   0.12489996  Yeast_cells_10e3    No_probes   N
N_probes_high   52151795.3333333    17821525.3998365    49478020.3333333    16944505.0930496    94.8633333333   0.2668957349    1431383.66666667    460221.541108555    2.76    0.0754983444    2.2466666667    0.2419366308    48033411.3333333    16480091.6076972    426476.666666667    124704.889175739    99.1033333333   0.086216781 0.8966666667    0.086216781 98291834.3333333    33702623.8020829    955178.666666667    285482.724103112    99.0233333333   0.0763762616    0.9766666667    0.0763762616    Yeast_cells_10e5    With_probes N
N_probes_low    825738.666666667    569155.018799214    778522.333333333    537528.039274542    94.0433333333   0.6296295207    24706   17027.1162855018    3.0033333333    0.0404145188    2.9333333333    0.5980245257    651787.333333333    447581.778119187    105189.333333333    75067.0266983669    86.31   0.6757958272    13.69   0.6757958272    1333443.33333333    916506.721464351    232336.666666667    165105.510039288    85.3633333333   0.6184927917    14.6366666667   0.6184927917    Yeast_cells_10e3    With_probes N
T_high  48689209.6666667    2848113.91636805    44582654.6666667    2459514.32442512    91.58   1.2315843455    1667428.66666667    94978.9842772249    3.4266666667    0.0513160144    4.9433333333    1.1991802756    26208616.6666667    1706128.05843123    16442090    2541042.37807774    61.5433333333   4.6120422085    38.4566666667   4.6120422085    54808833    3472179.81522256    34684155    5314609.17021384    61.34   4.5696389354    38.66   4.5696389354    Yeast_cells_10e5    No_probes   T
T_low   38211620.3333333    3165849.17317129    32698052.6666667    3022170.15101968    85.56   2.7296336751    1252415.33333333    140042.92600604 3.27    0.1228820573    11.0866666667   2.6616035267    759404.333333333    109873.656789666    30463219.3333333    2759153.89398822    2.4266666667    0.2157158625    97.5733333333   0.2157158625    1589486.33333333    229003.915635374    64381590.3333333    5897792.37930578    2.4066666667    0.207926269 97.5933333333   0.207926269 Yeast_cells_10e3    No_probes   T
T_probes_high   17060485    10065981.0572141    16216312.6666667    9588092.069878  95.0166666667   0.4091861842    494533.666666667    283238.257728954    2.9133333333    0.0550757055    1.9733333333    0.3622614157    15725821    9220741.40167226    152331  149671.584788162    99.1733333333   0.3419551628    0.8266666667    0.3419551628    32202007.3333333    18912407.9486687    324222  318070.963610324    99.1433333333   0.3510460559    0.8566666667    0.3510460559    Yeast_cells_10e5    With_probes T
T_probes_low    419058.666666667    93338.5909810799    382539.666666667    85276.248916878 91.3    0.9755511263    13789.6666666667    3596.2633848668 3.27    0.2523885893    5.41    0.7617742448    278922  59532.6942696196    93764   23628.0924536874    74.9666666667   1.3444825523    25.0333333333   1.3444825523    571032.666666667    122954.866911942    200518  51626.958810296 74.15   1.5726410906    25.85   1.5726410906    Yeast_cells_10e3    With_probes T

Here is my code:

ggplot(with_mean_and_sd, aes(x=method, y=calb_mapped_pr.mean,label=paste0(round(calb_mapped_pr.mean,1),"%","\n", round(calb_mapped.mean,0)))) + 
  geom_bar(stat="identity", fill="dodgerblue2") + facet_grid(probes ~ yeast_count)+
  geom_errorbar(aes(ymin=calb_mapped_pr.mean-calb_mapped_pr.sd,
                    ymax=calb_mapped_pr.mean+calb_mapped_pr.sd),
                    width=.2,position=position_dodge(.9))+ylab("% of fungal reads")+
  xlab("Enrichment method")+geom_text(size = 4, y=25 ,position = position_stack(vjust = 0.5))+theme_bw()+
  theme(plot.title = element_text(hjust = 0.5),
        strip.text.x = element_text(size=12),
        strip.text.y = element_text(size=12), 
        axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=12),
        axis.title.x = element_text(size=12),
        axis.title.y = element_text(size=12))

The plot is here:

For each pair of barplots within each comparison group, I have calcualted p-values with pairwise.t.test.

My question is: How can I display the pairwise p-values on the barplots, to get something similar to here

Thanks

barplot ggplot2 R • 2.2k views
ADD COMMENTlink modified 14 months ago by RamRS25k • written 14 months ago by grant.hovhannisyan1.8k

I just corrected your image embed for you. See: How to add images to a Biostars post

ADD REPLYlink written 14 months ago by RamRS25k

Thanks Ram! For some reason the method you mention does not work for me.

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k

Right click -> Select image URL -> add to post doesn't work? That's an interesting bug. Can you give us your location (country), OS and browser please?

ADD REPLYlink modified 14 months ago • written 14 months ago by RamRS25k

Nope. Barcelona (Spain), Ubuntu 16.04 and both Chrome and Firefox

ADD REPLYlink modified 14 months ago • written 14 months ago by grant.hovhannisyan1.8k

Just to double check, you're using the image button on the toolbar to add the image? Can you reply to this comment with the URL you're using please?

ADD REPLYlink written 14 months ago by RamRS25k

Yes, I use the image button. enter image description here. Sorry, you mean the URL of the image? For example I use this URL https://ibb.co/gg0VHK

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k
2

That's not the URL to be used. You're using the URL of the page that hosts the image, not the URL to the image itself. The URL to the image usually ends in a file extension that is the same as the image file extension. For example, while your page URL is https://ibb.co/gg0VHK, the image URL is https://image.ibb.co/cLOT4z/fungal_RNA_comparisons.png - as you can see, it ends in .png and is obtained by right clicking on the image and selecting the "Copy Image Address" option.

ADD REPLYlink written 14 months ago by RamRS25k

Ah, so embarrassing, now it works :) Thanks for help Ram! Much appreciated!

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k

Say hello to Messi.

ADD REPLYlink written 14 months ago by Kevin Blighe52k

:) And you to Conor (if in Dublin) :)

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k

McGregor? ... ugghhh, won't be going near him!

ADD REPLYlink written 14 months ago by Kevin Blighe52k
3
gravatar for Kevin Blighe
14 months ago by
Kevin Blighe52k
Kevin Blighe52k wrote:

That guy just pulled that plot from this tutorial, where it explains how to do it: Add P-values and Significance Levels to ggplots

-----------------------------------

Another way is to do it manually via geom_segment() and geom_text(), as I did here: C: Implement p-values and significance levels in boxplots for more of two groups wi

d

Figure

By the way, your own plots look great! I will re-use that code.

Kevin

ADD COMMENTlink modified 14 months ago • written 14 months ago by Kevin Blighe52k
1

Hi Kevin, thanks for replies, I will try them out!

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k

By the way, I think I will add p values manually, ggpubr seems more complicated than common ggplot.

ADD REPLYlink written 14 months ago by grant.hovhannisyan1.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1998 users visited in the last hour