Reputation: 818
I am trying to produce a plot using ggplot2
on the UNvotes data. I am trying to parameterize the plot in Rmarkdown but getting the following error:
Error: Problem with `summarise()` input `perc_yes`. x non-numeric argument to binary operator i Input `perc_yes` is `sum(vote == "yes")/n`. i The error occurred in group 1: yr = 1991.
Code:
single_country %>%
inner_join(un_roll_calls %>% select(rcid, date), by = "rcid") %>%
mutate(yr = year(date)) %>%
group_by(yr) %>%
summarize(perc_yes = sum(vote == "yes") / n) %>%
ggplot(aes(x = yr, y = perc_yes)) +
geom_point() +
geom_line() +
labs(title = plot_title)
Not sure if it is lacking some recoding issues or so.
Upvotes: 1
Views: 36
Reputation: 79246
Change this line before ggplot
summarise(perc_yes = sum(vote == "yes") / n) %>%
with this line:
summarise(n = n(), perc_yes = sum(vote == "yes") / n) %>%
Actually you are missing n = n()
Upvotes: 1