dreamRs / esquisse

RStudio add-in to make plots interactively with ggplot2
https://dreamrs.github.io/esquisse
Other
1.76k stars 227 forks source link

Renaming variables while importing makes the output code unusable (comes with suggestion for solution) #265

Open daricomp opened 4 months ago

daricomp commented 4 months ago

Hi,

using esquisser() and then the GUI for Import and Update, the renaming of the column variables makes the output code not reusable, because the renamed columns do not correspond anymore to the original column names.

Example if I rename Sepal.Length in the iris dataset into Sepal.Lenght2, this is esquisse's output code:

ggplot(iris) + aes(x = Sepal.Length2) + geom_histogram(bins = 30L, fill = "#112446") + theme_minimal()

This code cannot work because in the environment the column is still iris$Sepal.Length.

Now, one solution would be to make the esquisse Import function use tidyverse before the ggplot command to do the renaming. Exemple of always working output code:

iris %>% rename(Sepal.Length2 = Sepal.Length) %>% ggplot() + aes(x = Sepal.Length2) + geom_histogram(bins = 30L, fill = "#112446") + theme_minimal()

Of course, the filter commands written by the esquisse Data tab (which already follow the syntax suggested here) should be placed after the rename command. Example:

iris %>% rename(Sepal.Length2 = Sepal.Length) %>% filter(Sepal.Length2 > 1) %>% ggplot() + aes(x = Sepal.Length2) + geom_histogram(bins = 30L, fill = "#112446") + theme_minimal()

pvictor commented 3 months ago

Yes this is problematic, we need to see how we can generate code in this module. There some work to be done, I cannot say when I'll get time to look at that.

Victor