-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
geom_textsegment() with arrow() draws line to the top left of the plot #66
Comments
Hi there, thanks for letting us know! I can reproduce this on the default windows device, but not using the {ragg} graphics device. Reprex with default windows device: library(geomtextpath)
#> Warning: package 'geomtextpath' was built under R version 4.1.2
#> Loading required package: ggplot2
ggplot(mapping = aes(x, y)) +
geom_col(
data = data.frame(x = c(1, 2), y = c(1, 10))
) +
annotate(
"textsegment",
x = 1, xend = 2, y = 1, yend = 10,
label = "10x increase", arrow = arrow()
) The graphical object should consist of 4 points, two of which for the path before the text and another two points for after the text. This seems to be correct as far is I can tell. g <- layer_grob(last_plot(), 2)[[1]]
g <- grid::makeContent(g)$children[[1]]
g$x
#> [1] 1.82535885167464inches 3.19303238122172inches 3.80683014391654inches
#> [4] 5.17464114832536inches
g$y
#> [1] 0.681818181818182inches 2.35233370719354inches 3.10204383162793inches
#> [4] 4.77272727272727inches Created on 2022-02-04 by the reprex package (v2.0.1) |
Thanks for the swift reply! While it would be nice to get this fixed for others (regardless of whether it's a bug in this package or in the Windows default graphics device), now I can make the plot I wanted using ragg. |
Although this is a quirk in the Windows device, we can track it down specifically to how it handles multiple If I start by recreating the plot: library(geomtextpath)
#> Loading required package: ggplot2
library(grid)
ggplot(mapping = aes(x, y)) +
geom_col(
data = data.frame(x = c(1, 2), y = c(1, 10))
) +
annotate(
"textsegment",
x = 1, xend = 2, y = 1, yend = 10,
label = "10x increase", arrow = arrow()
) Now we'll isolate the textpath and get it to generate grobs through g <- layer_grob(last_plot(), 2)[[1]]
g <- grid::makeContent(g)
grid.newpage()
grid.draw(g$children) Where we can see the problem persists. Now if we look at the g$children[[1]]$arrow
#> $angle
#> [1] NA 30
#>
#> $length
#> [1] 0.25inches 0.25inches
#>
#> $ends
#> [1] 2 2
#>
#> $type
#> [1] 1 1
#>
#> attr(,"class")
#> [1] "arrow" We will see that the first arrow isn't drawn because its angle is I'm not sure whether handling multiple arrow arguments, one of which is
There is no guarantee that this case would be handled well by other / future graphics devices, so I would be inclined to consider this a fixable bug in our code. Created on 2022-02-04 by the reprex package (v2.0.1) |
Nice sleuthing Alan! I'll PR in a fix |
As in the title,
geom_textsegment()
witharrow()
draws a line starting from where the text starts to the top left of the plot.Using the example from the docs:
The output:
sessionInfo():
This happens regardless if I use
geom_textsegment
as an annotation.The text was updated successfully, but these errors were encountered: