Clicking this first Code shows the setup code required before using R and RStudio to do other things.
In BUA 345, this code will ALWAYS be provided and is straightforward to run.
Code
```{r message=F}#|label: Setup# this line specifies options for default options for all R Chunksknitr::opts_chunk$set(echo=T, highlight=T)# suppress scientific notationoptions(scipen=100)# install helper package (pacman) if neededif (!require("pacman")) install.packages("pacman", repos = "http://lib.stat.cmu.edu/R/CRAN/")# install and load required packages# pacman should be first package in parentheses and then list otherspacman::p_load(pacman, tidyverse, gridExtra, magrittr)# verify packages (comment out in finished documents)# p_loaded()```
Import and Clean Data
In BUA 345, data management code will ALWAYS be provided and is straightforward to run.
Click the Code to see the R code below.
This code
imports the .csv file.
removes duplicates.
renames the variables to be lower-case (easier to work with).
creates a new categorical variable for Sex with order (levels) and labels as specified.
In BUA 345, data visualization code will ALWAYS be provided and is straightforward to run.
Click the Code to see the R code below.
This code creates a grouped bar plot comparing survival rate by sex with separate panels for each passenger class.
Code
```{r}#|label: Formatted Boxplot# grouped side_by_side boxplots with separate panel for each class(box_titanic <- titanic |> ggplot() + geom_bar(aes(x=sexF, fill=survived), position="dodge") + facet_grid(~class) + theme_classic() + scale_fill_brewer(palette = "Set1") + labs(title="Titanic Survival Demographics", y="Number of Passengers", x="", fill="Survived"))```
Next Steps
In BUA 345 you will learn
how to navigate the R/RStudio environment to run and examine provided code files.
how to create models and that analyze data like the data shown here.
how to interpret the model output to answer questions about the data.
Source Code
---title: "BUA 345 - Posit Cloud Demo"author: "Penelope Pooler Eisenbies"date: last-modifiedtoc: truetoc-depth: 3toc-location: lefttoc-title: "Table of Contents"toc-expand: 1format: html: code-line-numbers: true code-fold: true code-tools: trueexecute: echo: fencededitor: visual---## SetupClicking this first **Code** shows the `setup` code required before using R and RStudio to do other things.In BUA 345, this code will **ALWAYS** be provided and is straightforward to run.```{r message=F}#|label: Setup# this line specifies options for default options for all R Chunksknitr::opts_chunk$set(echo=T, highlight=T)# suppress scientific notationoptions(scipen=100)# install helper package (pacman) if neededif (!require("pacman")) install.packages("pacman", repos = "http://lib.stat.cmu.edu/R/CRAN/")# install and load required packages# pacman should be first package in parentheses and then list otherspacman::p_load(pacman, tidyverse, gridExtra, magrittr)# verify packages (comment out in finished documents)# p_loaded()```## Import and Clean DataIn BUA 345, data management code will **ALWAYS** be provided and is straightforward to run.Click the **Code** to see the R code below.This code- imports the .csv file.- removes duplicates.- renames the variables to be lower-case (easier to work with).- creates a new categorical variable for Sex with order (levels) and labels as specified.```{r}#|label: Import and manage Titanic data#|titanic <-read_csv("data/titanic.csv", show_col_types = F) # remove duplicates# rename variables # create a factor variable sexFtitanic <- titanic[!duplicated(titanic),] |>select(`SURVIVED?`, CLASS, GENDER) |>rename(survived=`SURVIVED?`, class=CLASS, gender=GENDER) |>mutate(sexF =factor(gender, levels =c("male", "female"), labels =c("Male", "Female")))```## Barplot of Titanic DataIn BUA 345, data visualization code will **ALWAYS** be provided and is straightforward to run.Click the **Code** to see the R code below.This code creates a grouped bar plot comparing survival rate by sex with separate panels for each passenger class.```{r}#|label: Formatted Boxplot# grouped side_by_side boxplots with separate panel for each class(box_titanic <- titanic |>ggplot() +geom_bar(aes(x=sexF, fill=survived), position="dodge") +facet_grid(~class) +theme_classic() +scale_fill_brewer(palette ="Set1") +labs(title="Titanic Survival Demographics", y="Number of Passengers", x="", fill="Survived"))```## Next StepsIn BUA 345 you will learn- how to navigate the R/RStudio environment to run and examine provided code files.- how to create models and that analyze data like the data shown here.- how to interpret the model output to answer questions about the data.