ggplot - 根据从先前管道传递的对象在 ggplot 中创建内部管道

问题描述 投票:0回答:1

我正在尝试这个非常简单的代码:

mtcars %>% 
  mutate(Bla = cyl+mpg) %>% 
  ggplot(. %>% 
           filter(am == 1), aes(x = mpg, y = cyl)) +
  geom_point()

它不起作用并给出错误

You've supplied a <fseq> object
。但是,以下工作有效:

ggplot(mtcars %>% 
         mutate(Bla = cyl+mpg) %>% 
         filter(am == 1), aes(x = mpg, y = cyl)) +
  geom_point()

因此,似乎不可能将点

.
参数传递给ggplot,然后沿着管道跟随它。

我发誓我曾经能够做到这一点,因此我的问题是:

  1. 这是否在 ggplot 中的某个时刻发生了变化,我只是在做旧的事情吗?或者这是不可能的,我做的完全错误?
  2. 如果确实改变了,那么现在传递这些点参数的首选和建议方法是什么?
r tidyverse
1个回答
0
投票

您需要添加 , 映射 = 才能使其工作

mtcars %>% 
  mutate(Bla = cyl+mpg) %>% 
  ggplot(. %>% filter(am == 1), mapping = aes(x = mpg, y = cyl)) +
    geom_point()
© www.soinside.com 2019 - 2024. All rights reserved.