相关疑难解决方法(0)

使用ggplot2在dplyr链中进行子集/过滤

我想做出slopegraph,沿着线(没有双关语意)的这个.理想情况下,我想在dplyr风格的链条中完成所有操作,但是当我尝试将数据子集化以添加特定geom_text标签时,我遇到了麻烦.这是一个玩具示例:

# make tbl:

df <- tibble(
  area = rep(c("Health", "Education"), 6),
  sub_area = rep(c("Staff", "Projects", "Activities"), 4),
  year = c(rep(2016, 6), rep(2017, 6)),
  value = rep(c(15000, 12000, 18000), 4)
) %>% arrange(area)


# plot: 

df %>% filter(area == "Health") %>% 
  ggplot() + 
  geom_line(aes(x = as.factor(year), y = value, 
            group = sub_area, color = sub_area), size = 2) + 
  geom_point(aes(x = as.factor(year), y = value, 
            group = sub_area, color = sub_area), size = 2) +
  theme_minimal(base_size …
Run Code Online (Sandbox Code Playgroud)

r subset ggplot2 dplyr

4
推荐指数
1
解决办法
3784
查看次数

标签 统计

dplyr ×1

ggplot2 ×1

r ×1

subset ×1