1

i have this data and plot

mydata <- data.frame(a=c(1:5),b=c(6:10),c=c(11:15),e=c(16:20))
plot <- stripchart(mydata, method="jitter", vertical=T,main='plot',pch=19)

I would like to subset the x axis into two labels named 'a+b' and 'c+d' labels

Thanks in advance

Sergio.pv
  • 1,380
  • 4
  • 14
  • 23
  • what do you mean by "subset the x axis"? what do you want the result to look like? Do you want to merge a and b, to show a common label in-between a and b or, in addition to the already existing a and b labels, to add a 'a+b' label below? – plannapus Dec 19 '13 at 12:05
  • Take a look at the `axis` function. – Thomas Dec 19 '13 at 12:06
  • @plannapus "or, in addition to the already existing a and b labels, to add a 'a+b' label below?" --> exactly! – Sergio.pv Dec 19 '13 at 12:09

1 Answers1

1

In your case you can simply use mtext on side 1:

mydata <- data.frame(a=c(1:5),b=c(6:10),c=c(11:15),d=c(16:20))
plot <- stripchart(mydata, method="jitter", vertical=T,main='plot',pch=19)
mtext(c('a+b','c+d'),side=1,line=3,at=c(1.5,3.5))

Argument line is to set up the vertical position and at the position on the x-axis.

Edit: To add a distance between the two groups, you can do like this (there may be a cleaner way to do that but that's the only one I can think of from the top of my head):

mydata <- data.frame(a=c(1:5),b=c(6:10),c=c(11:15),d=c(16:20))
plot <- stripchart(mydata, method="jitter", vertical=T, main='plot',pch=19, 
                   at=c(1,2,4,5),xlim=c(0,6))
mtext(c('a+b','c+d'),1,line=3,at=c(1.5,4.5))

Argument at of stripchart is the one to fiddle with, but you then have to modify the plot limits (xlim) and the x-value at which you write the axis label (in mtext).

plannapus
  • 18,529
  • 4
  • 72
  • 94