microsoft / datamations

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

Get a basic d3.js example working with r2d3 #5

Closed jhofman closed 3 years ago

jhofman commented 3 years ago

This package, r2d3, should allow you to execute d3.js files in R.

jhofman commented 3 years ago

This looks like it's sandboxed in its own svg. @giorgi-ghviniashvili, is this flexible enough for what we want to do?

jhofman commented 3 years ago

More documentation: https://rstudio.github.io/r2d3/

jhofman commented 3 years ago

See if you can pass a full dataframe from R to d3 using r2d3 and render a simple x-y scatter plot with the following data.

df <- data.frame(x = c(1,2,3), y = c(15,25,35), color = c('red','red','blue'))

If that works, try using the actual data in data-raw to create a plot where the x axis is degree (masters or phd), the y axis is salary, and points are colored by degree. (Jitter on the x axis is optional for now.)

Screen Shot 2021-04-05 at 2 23 29 PM

Bonus would be to turn this into an animation where the first frame is this scatter plot and the last frame shows only the averages in each group, as in the final frame of the demo animation from the R package. The animation should have all points in the first frame "flying into" the final average in its group in the last frame.

Screen Shot 2021-04-05 at 2 23 35 PM

The error bars are optional for now as well.

You can use this as a guide.

jhofman commented 3 years ago

The R for Data Science book is a good resource.

giorgi-ghviniashvili commented 3 years ago

Hi @jhofman .

I have done the scatterplot with csv data frame (read_csv).

Here is the video:

https://user-images.githubusercontent.com/6615532/113686906-d379a880-96d8-11eb-9df3-0c1d3005a16a.mov

Jitter done using d3.forceCollide.

Setup an interval method which just toggles between average or full view.

jhofman commented 3 years ago

Great.

After we resolve #2, let's get this code in a branch and then pull request if it's useful to keep it around.