R中的水平条形图

Ran*_*Raj 1 r bar-chart ggplot2

我正在尝试使用unvotes标记为每个问题类别“重要”的投票数的数据来重现水平条形图(如下所示)。问题按频率排序。我尝试了以下但停留在情节如何生成ggplot

柱状图

到目前为止我的方法:

library(dplyr)
library(unvotes)
library(ggplot2)

unique(issues$issue)
issues1 = issues %>% left_join(roll_calls)
issues1 %>%
  mutate(date2 = ymd(date)) %>%
  mutate(year = year(date2)) -> issues1
head(issues1)
Run Code Online (Sandbox Code Playgroud)

输出 dput

> dput(head(issues))
structure(list(rcid = c(77, 9001, 9002, 9003, 9004, 9005), short_name = c("me", 
"me", "me", "me", "me", "me"), issue = c("Palestinian conflict", 
"Palestinian conflict", "Palestinian conflict", "Palestinian conflict", 
"Palestinian conflict", "Palestinian conflict")), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)

Til*_*ill 5

library(tidyverse)
library(unvotes)
#> If you use data from the unvotes package, please cite the following:
#> 
#> Erik Voeten "Data and Analyses of Voting in the UN General Assembly" Routledge Handbook of International Organization, edited by Bob Reinalda (published May 27, 2013)

roll_calls_imp <- 
  un_roll_call_issues %>% 
  left_join(un_roll_calls) %>% 
  filter(importantvote == 1)
#> Joining, by = "rcid"

roll_calls_imp %>%
  count(issue) %>% # since we want to order the bars by frequency we count the values of `issue` ourselves instead of letting ggplot do the counting
  ggplot(aes(reorder(issue, n) , n)) + # the reorder command sorts the bars by frequency
  geom_col() +
  coord_flip()
Run Code Online (Sandbox Code Playgroud)