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

ggsave inproperly rendering geom_line with factored y-variable #4204

Closed
MartinEarle opened this issue Sep 19, 2020 · 2 comments · Fixed by #4448
Closed

ggsave inproperly rendering geom_line with factored y-variable #4204

MartinEarle opened this issue Sep 19, 2020 · 2 comments · Fixed by #4448
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@MartinEarle
Copy link

Hi,

I have come across a strange issue with ggsave() where it does not properly render a line if the y-variable is factored. It looks to me like it is ignoring the factoring, and plotting as if it was unfactored. It looks like this behavior does not occur when factoring the x-variable. When I use graphic devices like png() I do not have the issue. I did not include ggsave() or png() in the reprex because there is nowhere for the files to save, of course, but I have attached the output of each method below it.

library(tidyverse)

mtcars %>% 
  mutate(mpg = factor(mpg)) %>% 
  ggplot(aes(disp, mpg)) +
    geom_line(group = 1)

Created on 2020-09-19 by the reprex package (v0.3.0)

ggsave():
ggplot_output

png():
png_output

@yutannihilation
Copy link
Member

Thanks, seems reproducible. Curious...

library(tidyverse)

mtcars %>% 
  mutate(mpg = factor(mpg)) %>% 
  ggplot(aes(disp, mpg)) +
  geom_line(group = 1)

ggsave("tmp.png")
#> Saving 7 x 5 in image
knitr::include_graphics("tmp.png")

Created on 2020-09-19 by the reprex package (v0.3.0)

@thomasp85 thomasp85 added the bug an unexpected problem or unintended behavior label Mar 25, 2021
@thomasp85
Copy link
Member

The issue is somehow located in last_plot(), not ggsave... if you pass the plot object to ggsave it does what it should

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants