I am working with a Supreme Court dataset. I am trying to visualize the percentage of cases in each term that were decided by a one-vote margin. I have variables for terms, the number of votes in the majority, and the number of votes in the minority. The best option for visualization is a line graph with terms as the x-axis and the percentage of decisions made with a one-vote margin as the y-axis.
library(tidyverse)
library(dplyr)
scdby %>%
select(majVotes, minVotes, term)
I created a new variable for the vote margin.
scdbv %>%
select(majVotes, minVotes, term) %>%
mutate(margin = majVotes - minVotes)
Since then, I feel like I have tried every method under the sun to get the percent of single margin votes to apply in ggplot for my graph. This is the most recent method:
scdbv %>%
select(majVotes, minVotes, term) %>%
mutate(margin = majVotes - minVotes) %>%
mutate(margin1 = if_else(margin == "1", "1", "NA")) %>%
mutate(margin1 = as.integer(margin1)) %>%
ggplot(aes(x = term)) +
geom_line(aes(y = count(margin1) / n()))
Which returns:
no applicable method for 'groups' applied to an object of class "c('integer', 'numeric')"
I am sure there is something very simple I am missing with how to do this.