Kevin
Kevin

Reputation: 1122

R graphing: Making two plots closer together on the graph

I have a graph made with the code:

yvalue = c(100, -100, 50, 0)
xvalue = c(1, 1, 2, 2)
gmin = c(-100, 0)
gmax = c(100, 50)
xarrow = c(1, 2, 3, 4)
gplot = plot(xvalue, yvalue, xaxt="n", main="Just a graph", xlab="Groups", ylab="y-value")
xvaluenames = c("Group 1", "Group 2", 1, 2)
axis(1, at = 1:length(xvalue), labels = xvaluenames)
arrows(x0=xarrow, y0=gmin, x1=xarrow, y1=gmax, length=0)
abline(h=0)

Graph

I want Group 1 and Group 2 plots to be closer together. More like:

Better Graph

Does anyone have advise on how to get them closer together?

Upvotes: 3

Views: 1180

Answers (1)

Bernd Elkemann
Bernd Elkemann

Reputation: 23550

As an additional parameter to your graph() call you could add: xlim = c(x1,x2), where x1 and x2 are the limits of your visible x-axis.

In your case, since you are using x-coords 1 and 2 you could use xlim=c(0.5,2.5)

enter image description here

Upvotes: 3

Related Questions