在gghighlight_line R中放置标签

时间:2018-09-26 11:15:29

标签: r plot label

我正在用git add *.txt *.xml 绘制几个国家的时间序列。我已经使用以下代码成功绘制了一个包含各个国家趋势的多面图:

gghighlight_line

并生成以下情节:

enter image description here

现在,我正在尝试删除与每行关联的标签,并且我想知道oecd %>% filter(country %in% c("Germany", "France", "United Kingdom", "United States", "Canada", "Japan", "Italy", "Netherlands", "Spain")) %>% gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = max(pop_65) > 0, label_key = " ") + scale_x_discrete( breaks = c(2000, 2005, 2010, 2015)) + facet_wrap(~ country) + theme_minimal() 中是否有这样的选项。提前非常感谢

1 个答案:

答案 0 :(得分:1)

您可以添加参数use_direct_label = FALSE来删除行中的标签。

gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = 
                   max(pop_65) > 0, label_key = " ", use_direct_label = FALSE)

请注意,这不仅将它们从行中删除;还将标签直接放置在图例上。如果出于某种原因要完全隐藏它们,则可以在末尾添加:

oecd %>%
  filter(country %in% c("Germany", "France", "United Kingdom", "United States", 
"Canada", "Japan", "Italy", "Netherlands", "Spain")) %>%
gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = 
max(pop_65) > 0, label_key = " ") +
  scale_x_discrete( breaks = c(2000, 2005, 2010, 2015)) +
   facet_wrap(~ country) +
  theme_minimal() +
  theme(legend.position = "none")  # remove legend