Amherst-Statistics / IS5inR

Companion materials for De Veaux, Velleman, and Bock's "Intro Stats" 5th edition
MIT License
0 stars 3 forks source link

Chapter 3: gf_bar() #13

Closed nicholasjhorton closed 6 years ago

nicholasjhorton commented 6 years ago

gf_bar() automatically facets when there are multiple variables, and I'm not sure how to change it.

nicholasjhorton commented 6 years ago

Can you please give me an example of what it generates and what you are trying to generate?

mchien20 commented 6 years ago

library(mosaic) Titanic <- read_csv("http://nhorton.people.amherst.edu/is5/data/Titanic.csv") barplot(tally(~ Survived | Class, format = "percent", data = Titanic), beside = TRUE) barplot(tally(~ Class | Survived, format = "percent", data = Titanic)) gf_bar(~ Survived | Class, format = "percent", data = Titanic)

The first two plots are are the ones that I want, but gf_bar automatically facets.

nicholasjhorton commented 6 years ago

Do the commands:

library(mosaic) library(readr) Titanic <- read_csv("http://nhorton.people.amherst.edu/is5/data/Titanic.csv") gf_bar(~ Survived, fill = ~ Class, data = Titanic) gf_bar(~ Survived | Class, fill = ~ Survived, data = Titanic)

fit the bill?

mchien20 commented 6 years ago

The problem that I'm running into is that the bars in the stacked plot are proportions of each other: library(mosaic) library(readr) Titanic <- read_csv("http://nhorton.people.amherst.edu/is5/data/Titanic.csv") gf_percents(~ Survived, fill = ~ Class, data = Titanic)

nicholasjhorton commented 6 years ago

Can you try to replicate this using ggplot2?

nicholasjhorton commented 6 years ago

Can you please point me to your commit? Thanks in advance, Nick

mchien20 commented 6 years ago

https://github.com/Amherst-Statistics/IS5inR/commit/e2d06d3285591f73891dc86b9e23f25154396be5

nicholasjhorton commented 6 years ago

Thanks. Is the barplot() command still needed? Can you give the reader some sense of where the various displays show up in the chapter?