Skip to content

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

@joelostblom

Description

@joelostblom

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions