Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R graphing: Making two plots closer together on the graph

Tags:

plot

r

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?

like image 251
Kevin Avatar asked Feb 02 '26 06:02

Kevin


1 Answers

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

like image 65
Bernd Elkemann Avatar answered Feb 03 '26 21:02

Bernd Elkemann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!