You can specify xlim
and ylim
parameters to a plot() function call. Take a look at the segments() function to draw lines between (x
, y
) locations, within a plot.
#!/usr/bin/env Rscript
x1 <- c(982853, 983330, 2274704, 2274717, 976011, 976011, 983330, 1914374, 1914375)
x2 <- c(978000, 982868, 2275209, 2275209, 975597, 975600, 982919, 1914874, 1914874)
y1 <- rep(2, length(x1))
y2 <- rep(2, length(x2))
df <- data.frame(x1, x2, y1, y2)
pdf("foo.pdf", width=12, height=2)
plot(NA, xlim=c(min(df$x1),max(df$x2)), ylim=c(2,2), xlab="Position", ylab="y")
segments(df$x1, df$y1, df$x2, df$y2, lwd=2)
dev.off()
As mentioned, given the wide domain and narrow range, you're basically going to get dots:
And that's just using the domain around your specific dataset, not 0 to 3 Mb. You may need to consider alternative presentations of this data, or plotting subsets of it around smaller domains.
Also, given that some of your input regions overlap, you will want to jitter the y values of those overlapping regions. One simple way to do this is set up a fifth column with some random values, say drawn from a normal distribution of mean zero and s.d. of one. For each row, perturb the row's y1 and y2 values by that random number. Adjust the ylim values accordingly. This will usually separate overlapping regions:
#!/usr/bin/env Rscript
x1 <- c(982853, 983330, 2274704, 2274717, 976011, 976011, 983330, 1914374, 1914375)
x2 <- c(978000, 982868, 2275209, 2275209, 975597, 975600, 982919, 1914874, 1914874)
y1 <- rep(2, length(x1))
y2 <- rep(2, length(x2))
rnd <- rnorm(length(x1), 0, 1)
df <- data.frame(x1, x2, y1, y2, rnd)
pdf("foo.pdf", width=12, height=3)
plot(NA, xlim=c(min(df$x1),max(df$x2)), ylim=c(0,4), xlab="Position", ylab="y")
segments(df$x1, df$y1 + df$rnd, df$x2, df$y2 + df$rnd, lwd=2)
dev.off()
Now you can see the elements separate:
Thanks for the reply. How i need is, please find the image, portion of the image where the RE section is given.
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3925796/figure/fig3/
http://www.cookbook-r.com/Graphs/
I read the dataset as you have mentioned . Then I used
library(GenomicRanges)
followed by the below mentioned steps but I am getting error.
Can you please clarify on it.
Yaa got it.
Thanks everyone for the valuable comments. I just want a small clarification, if suppose I want to make my x-axis
something like 950000, 960000, 970000, 980000 so on till the end of this sample set. How can I fix the x-axis interval.
Using ggbio IRanges(950000, 3000000) is it possible to do?
I tried doing something like this
for eg:
But I am getting a black image in the plot window.The plotted lines are not clear.
Can you please help me out.