Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rscript plot for y-axis

    Hi

    I am plotting 2 y-axis graph. I have given the script

    pdf("plot.pdf")
    gene_lens<- read.table ('check.txt', header=FALSE)
    colnames(gene_lens)<- c('gene', 'control', 'IP')
    print(gene_lens$gene)
    par(mar=c(5,4,4,5)+.1)
    plot(gene_lens$gene, gene_lens$control, type='h', xlab='base position', ylim=c(0,1000), ylab='read depth', col="skyblue")
    par(new=TRUE)
    plot(gene_lens$gene, gene_lens$IP, type='h', xlab='base position', ylim=c(0,1000), ylab='read depth', col="red")
    legend("topleft",col=c("skyblue","red"),lty=1,legend=c("control","IP"))

    But it gives me y axis with 0, 200, 400, 600, 800, 1000. I just want 0, 500, 1000 to be on the scale. (Basically want to reduce the size of the graph). Kindly suggest any edition.

    Thanks
    Kushal

  • #2
    In future, it would be good to post a reproducible example, like including a small dummy data.frame for the "gene_lens" example you described. I made one up just to test, but I have no idea what your real data looks like.
    Easiest way to accomplish your goal is to add this to your plot() call:
    Code:
    [COLOR="RoyalBlue"]yaxt="n"[/COLOR]
    which will turn off printing the y-axis during the plot() call. Make sure to add it to both plot() commands.
    Then use the axis() function with your specific requirements:
    Code:
    axis(2, at=c(0, 500, 1000));
    I suggest adding xaxt="n" to the second plot() command, and silencing the second xlab and ylab so they wouldn't double-plot the labels (makes them look bold-pixelated.) Lastly, I didn't know how you intended to handle overlapping lines, so I improvised on line widths so I could see everything. Here is what I came up with:
    Code:
    gene_lens <- data.frame("gene"=c(100,500,750,900),
       "control"=c(10,50,240,890),
       "IP"=c(110,240,830,15));
    par("lend"="butt");
    plot(gene_lens$gene, gene_lens$control, type='h',
        xlab='base position', ylim=c(0,1000), ylab='read depth',
        col="skyblue3", [COLOR="RoyalBlue"]yaxt="n"[/COLOR], lwd=6);
    par("new"=TRUE);
    plot(gene_lens$gene, gene_lens$IP, type='h', xlab='',
        ylim=c(0,1000), ylab='', col="red", [COLOR="RoyalBlue"]yaxt="n"[/COLOR],
        xaxt="n", lwd=2);
    atN <- c(0, 500, 1000);
    axis(2, at=atN, labels=format(atN, big.mark=","), las=2);
    I added format() to the axis labels so the numbers are a little friendlier, the "las=2" part to make the axis labels perpendicular to the y-axis. Avoids people having to twist their heads sideways to read the labels. Makes them look like confused puppies. :-)

    Lastly, I'm not sure I'm familiar with this type of plot, but it seems like you're going for a sort of bar chart? If so, you may try the barplot2() function in the gplots package, something like this:
    Code:
    library(gplots);
    barplot2(t(as.matrix(gene_lens[,c("control", "IP")])), beside=TRUE,
       names.arg=gene_lens$gene, xlab='base position', col=c("seagreen", "orange"),
       yaxt="n", ylim=c(0,1000));
    axis(2, las=2, at=c(0,500,1000));

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Essential Discoveries and Tools in Epitranscriptomics
      by seqadmin




      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
      04-22-2024, 07:01 AM
    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, Yesterday, 08:47 AM
    0 responses
    16 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    60 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    60 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    54 views
    0 likes
    Last Post seqadmin  
    Working...
    X