0

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)
alko989
  • 7,688
  • 5
  • 39
  • 62
user2528935
  • 25
  • 1
  • 4
  • 1
    It is more useful to have a simple reproducible example ([great how-to here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)) keeping only the code that has to do with your question. About your question: I would do 2 plots on top of each other, setting the margin between them to zero and skipping the x-axis in the top one. – alko989 May 21 '14 at 12:00

2 Answers2

1

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))

enter image description here

Hope it helps,

alex

alko989
  • 7,688
  • 5
  • 39
  • 62
  • Thanks alex, I got it working by putting the following line in: gap.plot(x,y,gap=c(-25,25),col=col.vec,pch=16,cex=0.4,xlim=c(-200000,200000),ytics = seq(-100, 100, by = 25)) – user2528935 May 21 '14 at 16:27
0

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")

jlhoward
  • 58,004
  • 7
  • 97
  • 140