Unconfigured Ad

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

    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

    • mylaser
      Reply to Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
      by mylaser
      Kheloyaar: The Complete Guide to Kheloyaar Loginand Kheloyaar ID
      The online gaming industry has transformed the way people enjoy digital entertainment. As technology continues to improve, players are looking for platforms that offer convenience, security, and a seamless user experience. Kheloyaarhas gained attention among users who value an easy-to-use platform, quick account access, and a simple registration process.
      Whether you're exploring Kheloyaar for the first time or want to understand...
      Yesterday, 09:27 PM
    • SEQadmin2
      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
      by SEQadmin2



      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
      ...
      Yesterday, 11:10 AM
    • SEQadmin2
      Cancer Drug Resistance: The Lingering Barrier to Rising Survival
      by SEQadmin2



      Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

      There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
      07-08-2026, 05:17 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, Yesterday, 10:04 AM
    0 responses
    8 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 07-08-2026, 10:08 AM
    0 responses
    7 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 07-07-2026, 11:05 AM
    0 responses
    11 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 07-02-2026, 11:08 AM
    0 responses
    31 views
    0 reactions
    Last Post SEQadmin2  
    Working...