Error knittting Error in as.data.frame.default(x) : cannot coerce class 'c("gg", "ggplot")' to a data.frame

When I knit my .Rmd file, the following problem arises:

Quitting from lines 129-134 (stat_inf_project.Rmd) 
Error in as.data.frame.default(x) : cannot coerce class 'c("gg", "ggplot")' to a data.frame
Calls: <Anonymous> ... eval -> View -> as.data.frame -> as.data.frame.default
Ejecución interrumpida Please ask your questions about R Markdown here.

The lines 129-134 are:

Income_W_time<-gss%>%filter(race=="White")
Income_W_time_resume<-Income_W_time%>%filter(!is.na(income06))%>%group_by(year,income06)%>%summarise(Total=n())
gr_income_W_time<-ggplot(Income_W_time_resume,aes(x=income06,y=Total))+geom_col()+theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.5))+ggtitle("Distribución de ingresos anuales - raza blanca")+xlab("Rango ingresos")+ylab("Total encuestados")
gr_income_W_time+facet_grid(year ~ .)
View(gr_income_W_time)

I don't know what's wrong. I can run the chunk without problems

View is a function to show the data interactively in a GUI, R one or RStudio Table View.

You can't really use it in non-interactive way, like when compiling a Rmd document.

You should comment this out, and it should work I guess.

Thank you, very much!!

It worked perfectly.

Regards,

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.