Question

Here is my code for producing a rectangle plot, I would like to have the x and y axes labelled as they are specified below without them overlapping the labels "Index" and "NA" as seen below . Is there any way to remove the NA and Index labels or specify the labels I do want initially?

dat <- data.frame(x1=c(1,27,154.94056),
                  x2=c(27,154.94056,155.27056),
                  y=c(0.21294542,0.10480005,0.11760634))

> dat
#     x1       x2         y
#1   1.0000  27.0000 0.2129454
#2  27.0000 154.9406 0.1048001
#3 154.9406 155.2706 0.1176063

with(dat,plot(NA,xlim=c(min(x1),max(x2)),ylim=c(min(y),max(y)+.15),type="n"))
with(dat,rect(x1,y,x2,y+0.1))
title(xlab="chrX Position", ylab="Divergence")

enter image description here

Was it helpful?

Solution

In plot, set ylab='' and xlab='':

with(dat, plot(NA, xlim=c(min(x1),max(x2)),
                   ylim=c(min(y),max(y)+.15),
                   type="n", xlab='', ylab='')) # <- specify xlab and ylab here
with(dat, rect(x1,y,x2,y+0.1))
title(xlab="chrX Position", ylab="Divergence")

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top