library(dplyr)
library(datamations)

New data with added variable

small_salary <- dplyr::mutate(
  small_salary, 
  supplementalIncome = runif(nrow(small_salary), min = 60, max = 110),
  logNorm = rlnorm(nrow(small_salary), meanlog = 0, sdlog = 1)
  )

Log normal mutation

"small_salary %>%
  mutate(logged = log10(logNorm)) %>%
  group_by(Degree) %>%
  summarize(mean = mean(logged))" %>%
  datamation_sanddance()

Mathematical Notation

"small_salary %>%
  mutate(salarySquared = Salary^2) %>%
  group_by(Degree) %>%
  summarize(mean = mean(salarySquared))" %>%
  datamation_sanddance()
"small_salary %>%
  mutate(inverseSalary = 1 / Salary) %>%
  group_by(Degree) %>%
  summarize(mean = mean(inverseSalary))" %>%
  datamation_sanddance()

Multivariate

"small_salary %>%
  mutate(totalIncome = Salary + supplementalIncome) %>%
  group_by(Degree) %>%
  summarize(mean = mean(totalIncome))" %>%
  datamation_sanddance()
"small_salary %>%
  mutate(incomePer = Salary / supplementalIncome) %>%
  group_by(Degree) %>%
  summarize(mean = mean(incomePer))" %>%
  datamation_sanddance()

Mutations in a summarize

Currently the following statements error:

  1. summarize(z = sum(x + y))
  2. summarize(z = sum(x / y))
  3. summarize(z = sum(x) / sum(y))

Two variable mutates

Two variable mutates results in a warning, but does not error

"small_salary %>%
  mutate(totalIncome = Salary + supplementalIncome, squaredIncome = Salary^2) %>%
  group_by(Degree) %>%
  summarize(mean = mean(totalIncome))" %>%
  datamation_sanddance()
## Warning in generate_mapping(data_states, tidy_function_args, plot_mapping):
## Datamations currently only supports a single mutation call for visualization.
## Defaulting to the first provided new variable and discarding subsequent
## variables.