简体   繁体   English

在y轴上绘制两个范围

[英]Plot two ranges on y-axis

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. 我正在尝试编辑y轴,因此它只绘制从-20到100以及从20到100的范围。这是为了删除在-25到+25之间发生的大空白空间,因为我没有绘制数据在这个区域内。

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 以下是我到目前为止已完成的工作,非常感谢任何人提出的关于如何限制ylim范围以仅在-100:-20和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)

I just saw that you are using the plotrix package: 我刚刚看到您正在使用plotrix软件包:

The function you are looking for is ?gap.plot 您正在寻找的功能是?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 亚历克斯

Same thing using ggplot 使用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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM