【发布时间】:2019-10-02 15:15:57
【问题描述】:
我想针对我的response variable 为numeric cols 创建ggplots。
这是可重现的代码:
test = mpg %>% select_if(is.numeric) %>%
dplyr::select(-year) %>% nest(-cyl) %>%
mutate(ggplots = map(data,~ggplot(data = .x) + geom_point(aes(x = cyl, y = .x))))
test
# A tibble: 4 x 3
cyl data ggplots
<int> <list<df[,3]>> <list>
1 4 [81 x 3] <gg>
2 6 [79 x 3] <gg>
3 8 [70 x 3] <gg>
4 5 [4 x 3] <gg>
Warning message:
All elements of `...` must be named.
Did you want `data = c(displ, cty, hwy)`?
得到错误:
test$ggplots[[1]]
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (81): x, y
怎么了?
【问题讨论】:
-
你有
data=.x和aes(y=.x)。其中一个.x需要是data.frame/tibble,另一个需要是列名。你到底想画什么? -
试图将
cyl与所有其他numeric cols进行对比 -
澄清一下,您不希望按组绘制任何图,而是寻找针对其他变量绘制的
cyl?