This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.0.1 ✓ dplyr 1.0.0
## ✓ tidyr 1.1.0 ✓ stringr 1.4.0
## ✓ readr 2.1.1 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
cel <- read_csv(url("https://www.dropbox.com/s/4ebgnkdhhxo5rac/cel_volden_wiseman%20_coursera.csv?raw=1"))
## Rows: 10262 Columns: 38
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): thomas_name, st_name
## dbl (36): thomas_num, icpsr, congress, year, cd, dem, elected, female, votep...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
names(cel)
## [1] "thomas_num" "thomas_name" "icpsr" "congress"
## [5] "year" "st_name" "cd" "dem"
## [9] "elected" "female" "votepct" "dwnom1"
## [13] "deleg_size" "speaker" "subchr" "afam"
## [17] "latino" "votepct_sq" "power" "chair"
## [21] "state_leg" "state_leg_prof" "majority" "maj_leader"
## [25] "min_leader" "meddist" "majdist" "all_bills"
## [29] "all_aic" "all_abc" "all_pass" "all_law"
## [33] "les" "seniority" "benchmark" "expectation"
## [37] "TotalInParty" "RankInParty"
cle_115 <- cel %>%
filter(congress == 115)
cle_115 <- cle_115 %>%
mutate(
Gender = ifelse(female ==1, "Female","Male")
)
ggplot(cle_115,
aes(x= dwnom1,
y = all_pass,
color = Gender)) +
geom_point() +
labs(
x= "Ideology",
y= "Bills Passed",
color = "Gender"
) +
theme_minimal()
## Warning: Removed 6 rows containing missing values (geom_point).
cle_115 <- cle_115 %>%
mutate(
Majority = ifelse(majority ==1, "Majority", "Minority")
)
ggplot(cle_115,
aes(x= votepct,
y= all_pass,
color= Gender)) +
geom_point() +
facet_wrap(~Majority) +
scale_color_manual(
values = c("Male" = "green","Female" = "orange")
) +
labs(
x="Vote Percentage",
y="Bills Passed",
color = "Gender"
) +
theme_minimal()
## Warning: Removed 6 rows containing missing values (geom_point).
ggplot(cle_115,
aes(x= Majority,
y=les)) +
geom_boxplot() +
labs(
title= "LES in the 115th Congress",
x="Majority or Minority",
y="Legislative Effectiveness"
) +
theme_minimal()