Skip to content

autocomplete variable names within ggplot2 aes() calls #8444

Closed

Description

@kevinushey

Given the code:

library(ggplot2)
ggplot(mtcars, aes(...))

It would be useful if we provided autocompletion results for the column names from mtcars within the aesthetic mapping.

Activity

  1. iagogv3 commented on Nov 25, 2020

    @iagogv3

    A few later I added #8459 without having saw this issue. Is it maybe related?

  2. kevinushey commented on Nov 25, 2020

    @kevinushey
    CollaboratorAuthor

    This issue merely described an unimplemented feature; I suspect yours is similar.

  3. added
    autocompletion
    on Nov 25, 2020
  4. github-actions commented on May 25, 2021

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  5. added
    stale
    on May 25, 2021
  6. removed
    stale
    on May 25, 2021
  7. modified the milestone: Later on Jun 1, 2021
  8. mikebessuille commented on Jun 1, 2021

    @mikebessuille
    Contributor

    We believe this is low priority; unless additional users can justify the importance of this, we will likely not get to it in the near term.

  9. KyBroecker commented on Jan 5, 2023

    @KyBroecker

    Would LOVE to see this feature, as someone who does a lot of plotting with dfs with all sorts of column names, and sometimes you just cant remember what the exact column name was.

  10. 8 remaining items

  11. vladtarko commented on Dec 12, 2023

    @vladtarko

    The autocomplete works if you're using the pipe:

     mtcars |>
       ggplot(aes(...))
    
  12. JMLuther commented on Jan 11, 2024

    @JMLuther

    Autocompletion is a major convenience in ggplot functions.
    The only ggplot function that I use commonly that does not support it are the facet_ functions.
    It would save a bit of time if autocomplete could be implemented there as well. Thanks!

    eg, while typing last line here:

    Theoph %>% 
      ggplot(aes(Time, conc, group=Subject)) +
      geom_line() +
      facet_wrap(~Subject)
    
  13. self-assigned this
    on Feb 1, 2024
  14. kevinushey commented on Feb 2, 2024

    @kevinushey
    CollaboratorAuthor

    Coming to the next daily builds at https://dailies.rstudio.com. You should be able to see both aesthetics that are relevant to the current geom:

    Screenshot 2024-02-02 at 2 03 31 PM

    As well as variable names (if any) available from the dataset provided to the ggplot2 call.

    Screenshot 2024-02-02 at 2 03 37 PM

    We would greatly appreciate any testing and feedback!

  15. olivroy commented on Feb 5, 2024

    @olivroy
    Contributor

    Hi, it looks awesome!

    I would suggest that within the same aes() call, to remove already specified aes.

    here, should not suggest x.
    image

    However, it is fine that x is proposed in a subsequent aes() call.

    Second suggestion: after a pipe, suggestions disppear. Suggestions are not the columns, but objects in my global environment.
    image

    Maybe it would be better to revert to old behavior with the added benefit of completing aesthetics x, y, color etc. in aes() call, but leave the right side untouched?

  16. JMLuther commented on Feb 6, 2024

    @JMLuther

    Nice! thanks- variable name suggestions now work for facet_wrap for me (Windows; daily build 397).
    A little sluggish responsiveness on first run, but probably just due to other tasks running on my laptop.

  17. olivroy commented on Feb 7, 2024

    @olivroy
    Contributor

    @kevinushey an important test case is the following. with a pipe. IIRC, it worked pretty well before the feature.

    mtcars |>
      dplyr::mutate(zz = vs ** 2) |>
      ggplot(aes(<TAB1>, y = <TAB2>)) +
      geom_point() +
      geom_label(data = iris, aes(<TAB3>))

    In the first TAB1, I would expect aes and column names to show up. (including zz)
    image

    In TAB2, I would expect column names to show up
    image

    TAB3 works as expected currently,
    image

  18. kevinushey commented on Feb 7, 2024

    @kevinushey
    CollaboratorAuthor

    @olivroy many thanks; I will take a look!

  19. olivroy commented on Feb 8, 2024

    @olivroy
    Contributor

    Thanks for taking a look. Everything
    Just a tiny issue left I think.

    order of the aesthetics suggestions (every case)

    image

    Should override completions from aes(). (this worked correctly the first time. Problem piped or not.

    Piped data + 2 aes() calls with the same data.

    There is no variable completion in subsequent aes() calls for the same data: (my cursor is at shape = <TAB>

    image

    This works as expected when the data is not piped in.
    image

    still working as expected for a new data
    image

    And works ok after as well
    image

  20. olivroy commented on Feb 22, 2024

    @olivroy
    Contributor

    On the ggplot2 side, it mostly seems good with #14309.

    Maybe last tiny thing is that newly created variables show in the first aes() call, but not in the following ones.

    Shown: (note that some variables are missing, but this issue is a broader issue (that shows in other context) a fix to #14311 locks that in!
    image
    Not shown
    image

    library(tidyverse)
    mtcars |>
      tibble::rownames_to_column() |> 
      mutate(
        xz = vs ** 2,
        label = glue::glue("{rowname}, {hp}"),
        aaa = ifelse(gear >= 3, "yes", "no"),
        s2 = vs**2,
        f1 = case_when(
          s2 > 100 ~"Yes",
          .default = "No"
        )
      ) |>
      ggplot(aes(x = xz, y = disp)) +
      geom_point()+ 
      ggrepel::geom_text_repel(
        aes(label = label) # No new variable suggestion shown.
      )

    (Took a while to isolate things, but I think I have a good understanding now!)

  21. kevinushey commented on Feb 28, 2024

    @kevinushey
    CollaboratorAuthor

    I believe that issue ultimately comes down to a limitation in how RStudio's autocompletion system tries to find the correct pipe context for a statement. The fact that this code is mixing |> (dplyr pipes) and + (ggplot2 layer additions) causes trouble here.

    I'm going to file that as a separate issue to further enhance this autocompletion feature. #14342

  22. kevinushey commented on Feb 28, 2024

    @kevinushey
    CollaboratorAuthor

    Also, just to emphasize once more -- thanks @olivroy for taking the time to test each of these revisions; the feature is far more complete than it would have been without your help!

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

Metadata

Metadata

Assignees

Labels

autocompletionenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions