Hello, I was plotting ggplot and I found this error
Don't know how to automatically pick scale for object of type grouped_df/tbl_df/tbl/data.frame. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (502): y
My code is-
by_deathcause<-prostate_data_clean %>%
group_by(cause_of_death, status_) %>%
nest()
##building models
model1<-function(df){
lm(serum_hemoglobin~sdate, df)
}
#nesting and modelling
by_deathcause<-by_deathcause %>%
mutate(mdls=map(data,model1)) %>%
mutate(resids= map2(data, mdls, add_residuals),
pred=map2(data, mdls, add_predictions))
#unnest prediction
pred<-unnest(by_deathcause, pred)
resids<-unnest(by_deathcause, resids)
resids
#plot the prediction
pred %>%
ggplot(aes(sdate, pred, group=status_))+
geom_line()+
geom_smooth()
#want clearer view on each cause of death!
pred %>%
ggplot(aes(sdate, pred, group=status_))+
geom_line()+
facet_wrap(~status_)
#plot the residual !!!!!!!!!!!!
resids %>%
ggplot(aes(sdate, resids, group=cause_of_death))+
geom_line()+
geom_smooth(se=FALSE)
----------------------------------------------------------------------
I would really appreciate if you advise me how to solve the problem!
Thank you very much!