My code chunk runs on markdown, but when I try to knit my markdown it gives me this error:
Error in geom_point()
:
! Problem while setting up geom.
Error occurred in the 1st layer.
Caused by error in compute_geom_1()
:
! geom_point()
requires the following missing aesthetics: y
Backtrace:
- rmarkdown::render(...)
- knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
- knitr:::process_file(text, output)
- knitr:::process_group.block(group)
- knitr:::call_block(x)
... - ggplot2:::ggplot_build.ggplot(x)
- ggplot2:::by_layer(...)
- ggplot2 (local) f(l = layers[[i]], d = data[[i]])
- l$compute_geom_1(d)
- ggplot2 (local) compute_geom_1(..., self = self)
Execution halted
Here is my code:
if (!require("ggplot2")) install.packages("ggplot2")
library(ggplot2)
aa_score <- (ghana_map$"Aedes aegypti score")
ggplot(ghana_map, aes(x = HDI, y = aa_score, color = Water_access)) +
geom_point(size = 1, stroke = 0.5) +
geom_hline(yintercept = 0, color = "black", linetype = "solid") +
geom_vline(xintercept = 0.5, color = "black", linetype = "solid") +
labs(x = "HDI", y = "Aedes Aegypti Score", color = "Water Access") +
theme_minimal() +
theme(
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"),
legend.position = "top",
legend.direction = "horizontal",
legend.box.background = element_rect(color = "black", size = 0.5),
legend.title.align = 0.5,
legend.text.align = 0.5
) +
guides(color = guide_legend(override.aes = list(fill = "white")))