Comments (4)
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)
Whereas with ragg everything goes fine:
from geomtextpath.
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.
from geomtextpath.
Although this is a quirk in the Windows device, we can track it down specifically to how it handles multiple arrow
specifications for a polylinegrob
. In particular, it seems to be thrown by having an NA
passed as one of the angle
arguments.
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 makeContent
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 arrow
argument
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 NA
.
I'm not sure whether handling multiple arrow arguments, one of which is NA
, is a defined behaviour in a polyline grob. Therefore, we could fix this problem by changing the angle = NA
method of switching off the arrow to giving it a length value of 0:
g$children[[1]]$arrow$angle <- c(30, 30)
g$children[[1]]$arrow$length <- unit(c(0, 0.25), "in")
grid.newpage()
grid.draw(g$children)
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)
from geomtextpath.
Nice sleuthing Alan! I'll PR in a fix
from geomtextpath.
Related Issues (20)
- Long labels with arrow throw cryptic "Error: Cannot create zero-length unit vector ("unit" subsetting)" error
- Strange behaviour of halign HOT 4
- Feature Request: Set angle for geom_labelvline HOT 6
- Feature request - test for text self-overlap on sharp contours HOT 1
- ggplot coord_polar() issue with multiple classes: 'from' must be a finite number error HOT 1
- session aborted when library in Rstudio HOT 2
- text_only in geom_labelsegment
- Feature request - avoid text overlapping
- two labels on same curve HOT 5
- straight argument unknown in geom_textsf() HOT 2
- `label` aesthetic in `geom_textdensity2d` HOT 2
- R 4.3.0 and glyphs 👀 HOT 1
- Can't get things to work HOT 11
- vjust and hjust as aesthetics in geom_textsf HOT 3
- Different behavior for line breaks when there's no data
- geomtextline not accommodating RGBA colors
- show.legend not working in geom_textabline
- Support for `geom_step()`? HOT 2
- Partial match of 'xoff' to 'xoffset'
- geom_textsf seems to ignore remove_long=F
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geomtextpath.