R中的水平条形图
Horizontal barplot in R
我正在尝试重现水平条形图(如下所示),使用 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)
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"))
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()
我正在尝试重现水平条形图(如下所示),使用 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)
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"))
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()