我正在使用“ eurostat”软件包从eurostat下载数据。我的想法是建立一个条形图,比较最低工资与平均工资比率在2008年与2016年之间的变化。 但是我遇到的问题是选择时间(时间%in%c(“ 2008-01-01”,“ 2016-01-01”))。该行检索空的小标题。有什么建议我做错了吗? 非常感谢
可复制的示例”
library(tidyverse)
library(eurostat)
#retrieving data
earn_mw_avgr2 <- get_eurostat("earn_mw_avgr2", stringsAsFactors=FALSE)
#buidling bar plot
ggplot(data=earn_mw_avgr2 %>%filter(nace_r2=="B-S",
geo %in% c("EU", "BE","BG","CZ","DK","DE","EE","IE","EL","ES","FR","HR","IT","CY","LV","LT","LU","HU","MT","NL","AT","PL","PT","RO","SI","SK","FI","SE","UK"),
indic_se=="MW_MEAGE",
time %in% c("2008-01-01" ,"2016-01-01")),
aes(x=reorder(geo, values), y=values, fill=time))+
geom_bar(stat = "identity",
position = "dodge",
show.legend = FALSE)
答案 0 :(得分:1)
如果您尝试比较2008年与2016年,这应该会有所帮助
library(tidyverse)
library(eurostat)
library(lubridate)
ggplot(data=earn_mw_avgr2 %>%
#mutate(year = year(time)) %>% #No need to create a new column, implement lubridate::year function directly on time column
filter(nace_r2=="B-S",
geo %in% c("EU", "BE","BG","CZ","DK","DE","EE","IE","EL","ES","FR","HR","IT","CY","LV","LT","LU","HU","MT","NL","AT","PL","PT","RO","SI","SK","FI","SE","UK"),
indic_se=="MW_MEAGE",
year(time) %in% c("2008" ,"2016")),
aes(x=reorder(geo, values), y=values, fill=time))+
geom_bar(stat = "identity",
position = "dodge",
show.legend = FALSE)
答案 1 :(得分:0)
尝试
library(lubridate)
filter(year(time) %in% c(year("2008-01-01"), year("2016-01-01")))