ggquiver icon indicating copy to clipboard operation
ggquiver copied to clipboard

No check for equal proportions in plot

Open bart1 opened this issue 2 years ago • 5 comments

I just encountered this case, it seems geom_quiver does not check if the dimensions are equal between X and Y. This causes a problem that the directions of the arrows do not correct. This is easily fixable by using coord_equal or coord_fixed but it might be good to warn users to do so. Maybe it can be checked if the coord inherits CoordFixed, maybe a check for the ratio would also be good? (The first plot is incorrect)

d<-data.frame(t=Sys.time()+(3600*1:4), x=1000*c(1,-1), y=1000*c(1,1,-1,-1))
require(ggplot2)
#> Loading required package: ggplot2
require(ggquiver)
#> Loading required package: ggquiver
ggplot(d)+geom_quiver(aes(x=t, y=0, u=y,v=x))

ggplot(d)+geom_quiver(aes(x=t, y=0, u=y,v=x))+coord_equal()

Created on 2022-03-07 by the reprex package (v2.0.1)

bart1 avatar Mar 07 '22 21:03 bart1

Perhaps I'm missing something here, but is there a general requirement for the coordinates to be fixed? The arrows point to the same location in both plots, but have different angles when the plot's aspect ratio changes. I think this behaviour is expected when working with u and v as force offsets from the starting position.

It is definitely worth mentioning that when the arrow's angles are important, that using equal coordinate ratios for x and y axis is needed.

mitchelloharawild avatar Mar 07 '22 23:03 mitchelloharawild

Thanks for the reprex and clear explanation by the way! :tada:

mitchelloharawild avatar Mar 08 '22 02:03 mitchelloharawild

No problem, maybe it is not the case for all applications, for most applications I could see for the arrows the direction does matter. I encountered this when a student had some code where the arrows were pointing in a "wrong" direction. In our case it was a time series of vectors. As I know the u and v notation mostly from wind fields there the direction is important. I would say you know better how it is used and may see what the most common applications are.

bart1 avatar Mar 08 '22 07:03 bart1

For wind fields, I imagine it will be plotted on a map which would use the appropriate map coordinates. Perhaps I could add a message when the default ggplot2 coordinate space is used with geom_quiver(), suggesting that the angles may not be what is expected unless coord_equal() is used.

mitchelloharawild avatar Mar 08 '22 21:03 mitchelloharawild

In this case we were interested in a timeseries of wind to that is why the map did not have dimensions. I think that warning/message sounds sensible.

bart1 avatar Mar 09 '22 12:03 bart1