Reputation: 1573
I would like to make a scatterplot for a dataset that contains both positive and negative values. I am very familiar with plot() but I cannot find any option for moving the axes to center of the plot, i.e. at zero. I would like the plot to look like "crosshairs".
I know how to turn off the axes in plot(), i.e. xaxt = "N", and I understand how to use the axis(). There is no option or example that I can find to have the axes centered at zero in the middle of the plot. Using abline() to create the lines and tick marks seems unnecessary.
Can you please point me to a command, trick, or package that I can use with plot() to accomplish this goal?
Upvotes: 2
Views: 3550
Reputation: 23758
You need the axis
command. Look it up in the help. You can position the x-axis vertically and the y-axis horizontally.
Here's a little example.
plot(c(-2,2), c(-2,2), axes = FALSE, bty = 'n', panel.first = grid())
axis(1, c(-2, -1, 1, 2), pos = 0, cex.axis = 0.8)
axis(2, c(-2, -1, 1, 2), pos = 0, cex.axis = 0.8, las = 2)
Upvotes: 7