for example :
plot(1:10, 1:10)
grid(col="red")
Is it possible to rotate the red grid around the intersection of x axis and y axis (the origin {0,0}) , by an arbitrary angle ? It doesn't mean anything with this example but I want to do that.
for example :
plot(1:10, 1:10)
grid(col="red")
Is it possible to rotate the red grid around the intersection of x axis and y axis (the origin {0,0}) , by an arbitrary angle ? It doesn't mean anything with this example but I want to do that.
The grid function probably cannot do that in base R anyway. It's not an object-oriented plotting paradigm. I think you would come close with
abline
:It's a minor application of coordinate geometry to rotate by an arbitrary angle.
This does break down when angle = pi/2 so you might want to check this if building a function and in that case just use
grid
. The one problem I found was to get the spacing pleasing. If one iterates on the y- and x-axes with the same intervals you get "compression" of one of the set of gridlines. I think that is why the method breaks down at high angles.I'm thinking a more general solution might be to construct a set of grid end-points that spans and extends beyond the plot area by a factor of at least sqrt(2) and then apply a rotation matrix. And then use
segments
orlines
. Here is that implementation: