I am trying to display the regression coefficients as a bar chart with ggplot.
It concerns a regression analysis of the effects of the child's sex and family size on TV viewing. The regression analysis as found below works, the issue is in plotting the regression coefficients in a bar chart. When trying this, I get the following error message: Error: Aesthetics must be either length 1 or the same as the data (865): x, y.
Does anyone have any idea how to fix this?
tvview_model <- lm(views ~ sex + nrchildren,
data = tv_viewing) %>%
coeff_name <- names(tvview_model$coefficients) %>%
coeff_value <- coefficients(tvview_model) %>%
ggplot(data = tvview_model, aes(x = coeff_value, y = coeff_name)) +
geom_bar()