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

Assign the group_by variable to color and use two summarized variables on the xy-axes? #100

Open
joelostblom opened this issue Oct 1, 2021 · 1 comment

Comments

@joelostblom
Copy link

I am trying to replicate a plot like this from altair/vega:

import altair as alt
from vega_datasets import data

cars = data.cars()
alt.Chart(cars).mark_point().encode(
    x='mean(Weight_in_lbs)',
    y='mean(Miles_per_Gallon)',
    color='Origin')

image

I thought something like this might do it, but it keeps the grouped variable on the x-axis instead of assigning it to the color, and also drops one of the summarized variables. Is it possible to specify which variable should go where?

library(datamations)
library(dplyr)

"cars %>% 
  group_by(Origin) %>%
  summarize(Weight_in_lbs = mean(Weight_in_lbs),
            Miles_per_Gallon = mean(Miles_per_Gallon))" %>%
  datamation_sanddance()

image

@sharlagelfand
Copy link
Collaborator

Hi @joelostblom! In general, it is possible to specify which variables goes where by passing the spec as ggplot2 code, as in this example from the README:

"small_salary %>%
  group_by(Work, Degree) %>%
  summarize(mean_salary = mean(Salary)) %>%
  ggplot(aes(x = Work, y = mean_salary)) + 
  geom_point() + 
  facet_grid(rows = vars(Degree))" %>%
  datamation_sanddance()

README-mean_salary_group_by_degree_work_ggplot

As to your question about dropping one of the summarized values - right now we only support a single summarized value. There is an issue open for this (#53) so is definitely on our minds as a limitation!

@jhofman jhofman assigned jhofman and unassigned jhofman Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants