简体   繁体   中英

Plotting a bedgraph in ggplot2

I had previously been using the plotBedgraph function from the Sushi package to generate bedgraph plots, however I am currently trying to recreate this using ggplot2 as it was not compatible with other plot code that my lab is using.

A density plot seems suitable for the plot, but as an inexperienced R user coming from Python, I was unable to data-wrangle the correct arguments into the plot function. Would it be possible to replicate the below image in ggplot, perhaps as a density plot or another suitable plot function?

在此处输入图片说明

The data used to generate the plot is shown below:

chr13   0   41982   0.00000
chr13   41982   41994   0.10076
chr13   41994   42007   0.90151
chr13   42007   42009   1.73827
chr13   42009   42025   1.74104
chr13   42025   42040   2.55356
chr13   42040   42058   3.49472
chr13   42058   42072   4.29485
chr13   42072   42074   5.19204
chr13   42074   42076   4.29485
chr13   42076   42080   4.29924
chr13   42080   42085   4.30696
chr13   42085   42090   4.31473
chr13   42090   42093   4.32252
chr13   42093   42096   4.33021
chr13   42096   42099   4.33801
chr13   42099   42100   5.24009
chr13   42100   42107   4.33801
chr13   42107   42129   4.34580
chr13   42129   42145   3.54015
chr13   42145   42149   2.60059
chr13   42149   42164   2.57264
chr13   42164   42167   2.29211
chr13   42167   42190   2.57264
chr13   42190   42191   1.74104
chr13   42191   42193   2.57264
chr13   42193   42203   1.44231
chr13   42203   42212   1.74104
chr13   42212   42220   0.91309
chr13   42220   42221   0.96337
chr13   42221   42222   0.11592
chr13   42222   42225   0.16794
chr13   42225   42235   0.17174
chr13   42235   42242   0.17557
chr13   42242   42249   0.17939
chr13   42249   43000   0.00000

How about this?

ggplot(data) + geom_rect(aes(xmin=start,xmax=end,ymin=0,ymax=value))

It just draws each of your intervals as a filled rectangle, no wrangling required.

This doesn't fully reproduce the plotBedgraph from the Sushi package, but you could try:

ggplot(df, aes(x=start, y=value)) +
  geom_step() +
  theme_classic()

It's missing the fill but otherwise gets fairly close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM