Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 27, 2021 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/5510058d729aac8f0ea0e16172b523a3 to your computer and use it in GitHub Desktop.
Save codecademydev/5510058d729aac8f0ea0e16172b523a3 to your computer and use it in GitHub Desktop.
Codecademy export
---
title: "Museums and Nature Centers"
output:
html_document:
df_print: paged
---
```{r data, message=FALSE}
library(dplyr)
library(ggplot2)
library(stringr)
library(tidyr)
library(plotrix)
```
## Data Exploration
```{r load, message=FALSE}
# Load file as data frame
museums_df <- read.csv("museums.csv")
```
```{r inspect, message=FALSE}
# Inspect data frame
head(museums_df)
```
## Museums by Type
```{r barplot, message=FALSE}
# Create and print bar plot by type
museum_type <- ggplot(data=museums_df,aes(x=Museum.Type)) + geom_bar() + scale_x_discrete(labels=scales::wrap_format(8))
museum_type
```
```{r barplot_museum, message=FALSE}
# Create and print bar plot by museum vs non-museum
museum_class <- ggplot(data=museums_df) + geom_bar(aes(x=Is.Museum)) + scale_x_discrete(labels=c("TRUE"="Museum", "FALSE"="Non-Museum"))
museum_class
```
```{r barplot_type, message=FALSE}
# Filter data frame to select states
museums_states <- museums_df %>%
filter(State..Administrative.Location. == "IL" | State..Administrative.Location. == "CA" | State..Administrative.Location. == "NY")
head(museums_states)
# Create and print bar plot with facets
museum_facet <- ggplot(data=museums_states) + geom_bar(aes(x=Is.Museum)) + scale_x_discrete(labels=c("TRUE"="Museum", "FALSE"="Non-Museum")) + facet_grid(cols=vars(State..Administrative.Location.))
museum_facet
```
```{r barplot_stack, message=FALSE}
# Create and print stacked bar plot
museum_stacked <- ggplot(data=museums_df) +
geom_bar(
aes(x=factor(Region.Code..AAM.)),
fill=Is.Museum,
position = "stack") +
scale_x_discrete(
labels = c(
"1" = "New England",
"2" = "Mid-Atlantic",
"3" = "Southeastern",
"4" = "Midwest",
"5" = "Mountain Plains",
"6" = "Western")) +
scale_fill_discrete(
labels = c(
"FALSE" = "Non-Museum",
"TRUE" = "Museum"))
museum_stacked
```
## Museums by Revenue
```{r process, message=FALSE}
# Filter data frame
# Filter for only small museums
# Filter for only large museums
```
```{r histogram, message=FALSE}
# Create and print histogram
```
```{r boxplot, message=FALSE}
# Create and print boxplot
```
```{r mean, message=FALSE}
# Create and print bar plot with means
```
```{r mean_errorbar, message=FALSE}
# Calculate means and standard errors
# Create and print bar plot with means and standard errors
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment