Reputation: 25
I'm trying to edit the y-axis so it only plots ranges from -20 to 100 and 20 to 100. This is to remove the big empty white space that is occurring between -25 and +25 as I do not have data plotted within this region.
Below is what I have managed so far and would appreciate anyone's advice on how I can restrict the ylim ranges to only plot the axis between -100:-20 and 20:100
Thank you in advance
library(plotrix)
pdf("distance2gene.pdf")
data<-read.table("closest_gene_bed.txt",header=FALSE, sep="\t")
DM=data$V5
Distance=data$V15
col.vec=c(rep('olivedrab',length(Distance)))
ind=which(abs(Distance) < 5000)
col.vec[ind]= 'darkorchid4'
opt <- options(scipen = 10)
plot(Distance, DM, col= col.vec, pch = 16, cex =.4,ylim=range(-100,100),xlim=c(-500000,500000))
axis(side = 2, at = c(-100,-75,-50,-25,0,25,50,75,100))
axis.break(axis=2, breakpos=0, brw=0.05, style="slash")
options(opt)
Upvotes: 0
Views: 427
Reputation: 59375
Same thing using ggplot
set.seed(1)
y.up <- runif(100, 20, 100)
y.down <- runif(100, -100, -20)
library(ggplot2)
library(reshape2)
df <- data.frame(x=seq_len(100),y.up,y.down)
gg <- melt(df,id="x")
ggplot(gg, aes(x=x,y=value))+geom_point()+facet_grid(variable~.,scales="free")
Upvotes: 0
Reputation: 7918
I just saw that you are using the plotrix package:
The function you are looking for is ?gap.plot
Try something like:
library(plotrix)
set.seed(1)
y.up <- runif(100, 20, 100)
y.down <- runif(100, -100, -20)
gap.plot(1:200, c(y.up, y.down), gap=c(-20,20))
Hope it helps,
alex
Upvotes: 1