Giter Club home page Giter Club logo

Comments (4)

teunbrand avatar teunbrand commented on June 26, 2024

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:
image

from geomtextpath.

erikvona avatar erikvona commented on June 26, 2024

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.

AllanCameron avatar AllanCameron commented on June 26, 2024

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.

teunbrand avatar teunbrand commented on June 26, 2024

Nice sleuthing Alan! I'll PR in a fix

from geomtextpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.