Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aevgup
    Member
    • Jul 2011
    • 17

    #1

    plotting graph in R from a bed file

    Hi Everyone,

    I have a bed file. I am showing you a section of the bed file.

    Code:
    Slc19a1	81	144	1
    Slc19a1	192	255	6
    Slc19a1	273	336	7
    Slc19a1	363	426	4
    Slc19a1	465	528	3
    Slc19a1	540	603	5
    Slc19a1	813	876	5
    Slc19a1	912	975	6
    Slc19a1	987	1050	8
    Slc19a1	1062	1125	6
    Slc19a1	1170	1233	8
    Slc19a1	1278	1341	6
    The 4th column is the number of reads for particular interval. For eg the read count is 6 for the interval 192-255.

    I want to draw a histogram in R for these intervals with x axis having the intervals and y axis the counts

    How can I do it. I am a beginner in R.

    Thanks for the help

    Regards
  • ECO
    --Site Admin--
    • Oct 2007
    • 1360

    #2
    There will be a lot of fiddling to get it to look better, but here is my approach.

    1. Get the data into a dataframe.

    I use this function to read from the clipboard on a mac. You can also use read.table to read the whole bed file more efficiently:

    Code:
    >cboardf<- function(){
    >read.table(pipe("pbpaste"),sep='\t',header=F)}
    
    > d <- cboardf()
    
    > str(d)
    'data.frame':	12 obs. of  4 variables:
     $ V1: Factor w/ 1 level "Slc19a1": 1 1 1 1 1 1 1 1 1 1 ...
     $ V2: int  81 192 273 363 465 540 813 912 987 1062 ...
     $ V3: int  144 255 336 426 528 603 876 975 1050 1125 ...
     $ V4: int  1 6 7 4 3 5 5 6 8 6 ...
    2. Then you need to make a "name" for your regions...just a string...

    Code:
    > d$V5 <- paste(d$V2,"-",d$V3)  #make a new string for the region in column called V5
    
    > str(d)
    'data.frame':	12 obs. of  5 variables:
     $ V1: Factor w/ 1 level "Slc19a1": 1 1 1 1 1 1 1 1 1 1 ...
     $ V2: int  81 192 273 363 465 540 813 912 987 1062 ...
     $ V3: int  144 255 336 426 528 603 876 975 1050 1125 ...
     $ V4: int  1 6 7 4 3 5 5 6 8 6 ...
     $ V5: chr  "81 - 144" "192 - 255" "273 - 336" "363 - 426" ...
    3. Then make a plot (using ggplot2)

    Code:
    qplot(V5,V4,data=d,geom='bar') + opts(axis.text.x=theme_text(angle=90))
    Voila:


    You'll have to work a lot harder to make it look better, label axes is easy, sorting the X regions is more annoying, but pretty easy.

    Good luck.

    Comment

    Latest Articles

    Collapse

    • SEQadmin2
      Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
      by SEQadmin2



      CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

      Despite this, “CRISPR helped turn genome editing from a specialized technique into
      ...
      07-31-2026, 11:01 AM
    • SEQadmin2
      Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
      by SEQadmin2


      Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

      The systematic characterization of the human proteome has
      ...
      07-20-2026, 11:48 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, Yesterday, 12:22 PM
    0 responses
    12 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 08-11-2026, 10:35 AM
    0 responses
    14 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 08-06-2026, 07:41 AM
    0 responses
    31 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 08-03-2026, 10:13 AM
    0 responses
    49 views
    0 reactions
    Last Post SEQadmin2  
    Working...