microsoft / datamations

https://microsoft.github.io/datamations/
Other
67 stars 15 forks source link

Error if the data set already contains a column `y` #66

Closed sharlagelfand closed 3 years ago

sharlagelfand commented 3 years ago

Currently the code errors if there's already a column in the data named y (and will definitely be an issue if the variable being summarised or grouped is named y) because we're using that internally - need to dig in and rename to a more "system" type of name, same for x. I don't think we can use something like .x and .y. (which would be more like "systems names" in R) because they won't work with JS, so probably just something like datamations_x and datamations_y

@giorgi-ghviniashvili does the JS code use the actual "x" and "y" (and "y_raw") variables, or just looks for what is in the "x" and "y" encoding in the specs? Just trying to figure out if we need to coordinate changing this

library(dplyr)
library(ggplot2)
library(datamations)

diamonds_sample <- diamonds %>%
  sample_n(10)

diamonds_sample
#> # A tibble: 10 x 10
#>    carat cut     color clarity depth table price     x     y     z
#>    <dbl> <ord>   <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
#>  1  0.53 Ideal   F     VS1      62.2    55  1812  5.17  5.22  3.23
#>  2  0.39 Ideal   F     VS1      62.2    56  1024  4.7   4.63  2.9 
#>  3  0.55 Ideal   E     VS1      61.6    55  1940  5.33  5.28  3.27
#>  4  0.32 Ideal   E     VS2      62      55   900  4.41  4.39  2.73
#>  5  0.41 Premium G     SI1      62.7    55   923  4.8   4.77  3   
#>  6  0.52 Ideal   E     VVS2     62      54  2230  5.16  5.19  3.21
#>  7  0.4  Ideal   G     VS2      62.3    54   792  4.73  4.77  2.96
#>  8  1.54 Premium G     SI1      63      59  8176  7.31  7.26  4.59
#>  9  1.35 Premium G     VS2      62.7    56  9253  7.08  7.05  4.43
#> 10  0.8  Ideal   I     VS2      62.6    54  2694  5.93  5.96  3.72

"diamonds_sample %>% group_by(cut) %>% summarise(mean = mean(price))" %>%
  datamation_sanddance()
#> Error: Names must be unique.
#> x These names are duplicated:
#>   * "y" at locations 7 and 9.
giorgi-ghviniashvili commented 3 years ago

@sharlagelfand yes, for facet faking I use "x" and "y" hardcoded. Like the idea of datamations_x and datamations_y.

jhofman commented 3 years ago

Agree on datamations_x and datamations_y. To facilitate merging correctly, @giorgi-ghviniashvili can make the update to the JS side first, then @sharlagelfand will pull in the changes to htmlwidget and reflect them on the R side.

giorgi-ghviniashvili commented 3 years ago

Hi, I created config.js and specified this field name there. See this commit.

You can change datamation_x to anything else, e.g. dub_dub_x, dub_dub_y.

image

sharlagelfand commented 3 years ago

Thanks @giorgi-ghviniashvili! I integrated that code into mine and also added a config file on the R side so it's not hard coded throughout - good idea! Seems to be working well, haven't found any cases where it breaks 🤞🏻. I'll create a pull request with the changes!