preselect <- read.csv(file="presidentialElections.csv", header=TRUE)
summary(preselect)
## X state demVote year
## Min. : 1 Length:1097 Min. :10.09 Min. :1932
## 1st Qu.: 275 Class :character 1st Qu.:40.18 1st Qu.:1952
## Median : 549 Mode :character Median :47.09 Median :1976
## Mean : 549 Mean :48.36 Mean :1975
## 3rd Qu.: 823 3rd Qu.:54.41 3rd Qu.:1996
## Max. :1097 Max. :98.57 Max. :2016
## south
## Mode :logical
## FALSE:857
## TRUE :240
##
##
##
mean(preselect$demVote)
## [1] 48.3594
median(preselect$demVote)
## [1] 47.09
max(preselect$demVote)
## [1] 98.57
min(preselect$demVote)
## [1] 10.09
Election <- data.frame(preselect)
ElectionData <- data.frame(Election$X, Election$state, Election$demVote, Election$year)
colnames(ElectionData) <- c("Count", "State", "DemVote", "Year")
demPercent <- (Election$demVote/100)
View(ElectionData)
ElectionPercent <-data.frame(Election$X, Election$state, demPercent, Election$year)
colnames(ElectionPercent) <- c("Count", "State", "DemVote", "Year")
View(ElectionPercent)
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
ElectionPercent %>%
filter(State == "California") %>%
summary(ElectionPercent)
## Count State DemVote Year
## Min. : 4.0 Length:22 Min. :0.3591 Min. :1932
## 1st Qu.: 255.0 Class :character 1st Qu.:0.4506 1st Qu.:1953
## Median : 516.5 Mode :character Median :0.5032 Median :1974
## Mean : 520.9 Mean :0.5130 Mean :1974
## 3rd Qu.: 784.2 3rd Qu.:0.5817 3rd Qu.:1995
## Max. :1052.0 Max. :0.6695 Max. :2016
library(ggplot2)
ggplot(data = ElectionPercent, aes(x = Year, y = DemVote , color = State)) +
geom_line()+ facet_wrap(~State) + theme(legend.position = "none") +
labs(x="", y="", title="Democtatic Presidential Voting Percentage by State by Year from 1930-2016") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size=6)) +
theme(axis.text.y = element_text(hjust = 1, size=6))
The data shows that in the Sate of California, for Presidential Elections, voters voted for a Democratic Presidential Candidate the most at 66.95% and the least at 35.91%. 1980, when Ronald Reagan ran for president was the low point as he was a Republican Candidate and a former Governor of California. The highest voting percentage was way back in 1936.