Skip to content

geom_line() render thread runs at 100%, apparently indefinitely, on wide-ranged input #5979

Closed
@twest820

Description

@twest820

Stumbled on this particular breakdown while looking at some fast(er) math things. ggplot 3.5.1 on R 4.4.0 with ragg 1.3.0 and RStudio 2024.04.2+764.

library(dplyr)
library(ggplot2)

theme_set(theme_bw() + theme(axis.line = element_line(linewidth = 0.3), panel.border = element_blank()))

arctan = tibble(theta = seq(0, 360), x = cos(pi/180 * theta), y = sin(pi / 180 * theta), quadrant = factor(if_else(x >= 0, if_else(y >= 0, 1, 4), if_else(y >= 0, 2, 3))), 
                arctan = atan2(y, x),
                yx = y/x, 
                horner = yx * (0.99997726 + yx^2 * (-0.33262347 + yx^2 * (0.19354346 + yx^2 * (-0.11643287 + yx^2 * (0.05265332 - yx^2 * 0.01172120))))))

ggplot() +
  geom_line(aes(x = y/x, y = arctan, group = quadrant, color = quadrant, linetype = "atan2"), arctan) +
  geom_line(aes(x = y/x, y = horner, group = quadrant, color = quadrant, linetype = "Horner"), arctan) +
  coord_cartesian(xlim = c(-1, 1) * 10, ylim = c(-1, 1) * pi) +
  labs(x = "y/x", y = "atan2(y, x)", color = "quadrant", linetype = "implementation")
# quickly shows console prompt but never renders and prompt doesn't take new input

Interrupt has no effect so recovery's via killing the R session and restarting.

Workaround's to only plot the 90° wedges of the circle where the Horner polynomial's well posed. This restricts the plotted y values to less than ±1 rather than going up to 10¹⁷⁶ or so.

arctan %>% filter(yx >= -1, yx <= 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions