Skip to content
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

empty plot with secondary axis fails #4509

Closed
FBartos opened this issue Jun 13, 2021 · 0 comments · Fixed by #4682
Closed

empty plot with secondary axis fails #4509

FBartos opened this issue Jun 13, 2021 · 0 comments · Fixed by #4682
Labels
bug an unexpected problem or unintended behavior scales 🐍

Comments

@FBartos
Copy link

FBartos commented Jun 13, 2021

Hi,

I randomly encountered a bug while working with the ggplot package. I was trying to create an empty plot with secondary (so other functions in my package can fill it up later). However, adding the secondary axis to an empty ggplot object throws an error if the object is called.

E.g.,:

plot <- ggplot2::ggplot() 
plot <- plot + ggplot2::scale_y_continuous(
  name = "ylab", limits = c(0, 1), 
  sec.axis = ggplot2::sec_axis(~ ., name = "ylab2", breaks = c(0, 1), labels = c(0, 2)))

which throws this error when calling plot

Error in seq.default(range[1], range[2], length.out = self$detail) :
'from' must be of length 1

However, adding a geom (either before or after adding the secondary axis) fixes the issue:

plot + ggplot2::geom_point(data = data.frame(x = 0.5, y = 0.5), mapping = ggplot2::aes(x = x, y = y))

Best,
Frantisek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants