library(ggmosaic)
library(dplyr)
library(purrr)
library(tidyr)
library(broom)
library(tibble)
使用下面的代码,我希望该函数同时输出 tidy tibble 和 ggplot。我不确定如何在函数中使用“return”来返回不止一件事。
我尝试过这样的事情......
Chifun<-function(var){
df<-happy%>%select(-id,-year,-age,-wtssall)%>%
map(~chisq.test(.x,happy[,var]))%>%
tibble(names=names(.),data=.)%>%
mutate(stats=map(data,tidy))%>%unnest(stats)
GG<-ggplot(df)+ geom_col(aes_string(x="names",y="p.value"))
return(df,GG)}
……还有这个……
Chifun<-function(var){
df<-happy%>%select(-id,-year,-age,-wtssall)%>% map(~chisq.test(.x,happy[,var]))
%>%tibble(names=names(.),data=.)%>%
mutate(stats=map(data,tidy))%>%unnest(stats)
return(df)
GG<-function(var){ggplot(df)+
geom_col(aes_string(x="names",y="p.value"))
return(GG)
}
}
我已经尝试了一些其他的变化,所以任何帮助将不胜感激。