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

Better documentation of xseq for stat_smooth() #5246

Closed
larmarange opened this issue Mar 23, 2023 · 6 comments · Fixed by #5466
Closed

Better documentation of xseq for stat_smooth() #5246

larmarange opened this issue Mar 23, 2023 · 6 comments · Fixed by #5466

Comments

@larmarange
Copy link

The xseq argument is a sort of hidden option for stat_smooth() allowing to select where to draw the smooth line.

Would it be relevant to mention it in the documentation and eventually to provide an example?

@teunbrand
Copy link
Collaborator

I'm not sure if it is hidden on purpose or not, but typically such options aren't advertised to users because they're considered internal.

@thomasp85
Copy link
Member

Given it's presence in compute_group it is exposed to users, whether we document it or not... My guess is that it has been omitted by an error. I doubt @hadley can remember either way...

We should in general document all arguments available to users so the best way forward is to lift the argument up into the constructor and document it

@hadley
Copy link
Member

hadley commented Mar 24, 2023

It's pretty esoteric, so I think we should only bother to document it if it's really required.

@larmarange
Copy link
Author

It is more flexible that fullrange and quite useful to extend a line only to the left to show the intercept.

Currently fullrange = TRUE extend to both side. There is no option fullrange = "right" or fullrange = "left" but it could easily be done through xseq.

See an old discussion like https://stackoverflow.com/questions/26705554/extend-geom-smooth-in-a-single-direction

@hadley
Copy link
Member

hadley commented Mar 24, 2023

If folks need that capability, these days I'd recommend that they fit the model themselves.

@teunbrand teunbrand added messages requests for improvements to error, warning, or feedback messages documentation and removed messages requests for improvements to error, warning, or feedback messages labels Mar 27, 2023
@EvaMaeRey
Copy link

EvaMaeRey commented Oct 6, 2023

@teunbrand gave me a heads up about this issue, so dropping in another possible (bespoke?) pedagogical xseq use, of adding fitted values of the observed values of x as points along smooth line. And also segments between these fitted values and raw data, giving residuals:

mtcars |> 
  ggplot(aes(wt, mpg)) +
  geom_point() +
  geom_smooth() + 
  stat_smooth(geom = "point",                  # draw fitted values as points
                        color = "blue",                   
                        xseq = mtcars$wt) +
  stat_smooth(geom = "segment",            # draw residuals
                         color = "darkred",       
                         xseq = mtcars$wt,
                         xend = mtcars$wt,
                         yend = mtcars$mpg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants