Referencing piped dataset in ggplot layers for subsetting

限于喜欢 提交于 2019-12-06 10:09:22

You could try using dplyr:

library(dplyr)
library(ggplot2)

read_excel("Book1.xlsx",sheet = "Sheet2") %>% 
  ggplot(aes(x, y)) +
  geom_col() +
  geom_point(data = . %>% filter(ID == "1"), colour = "red")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!