Rmarkdown won't knit: missing aesthetics error

Hi everyone,

Very new to Rmarkdown and I have been trying to knit it to pdf. However, it displays the following error message: ERROR: stat_smooth requires the following missing aesthetics: x, y

The line it has a problem with is this:

ggplot(GWASRAW, aes(x=GWASRAW$BASE_AGE1_R1, y=GWASRAW$BIO_MTB_LIPID_CE_R1, color=GWASRAW$BASE_SEX_R1)) + geom_point() + geom_smooth(method=`loess`) + scale_color_manual(values=c("darkmagenta", "darkcyan"), name= "Sex", labels=c("Female", "Male")) + xlab("Age (years)") + ylab("Cholesteryl esters (micromol)") 

I have specified all the packages needed in a previous chunk and established the path to the dataset (GWASRAW) in a previous chunk, which does run

GWASRAW <- read.csv2('/Volumes//GWASRAW.RData')

I have also tried specifying x and y by copying aes(x=GWASRAW$BASE_AGE1_R1, y=GWASRAW$BIO_MTB_LIPID_CE_R1, color=GWASRAW$BASE_SEX_R1) into the geom_smooth() code.
However, it still gives this error. Can anyone help me?

Thank you

Hi, welcome!
When working with ggplot, you don't have to use the $ syntax, since the ggplot() function has the data parameter where you already specify the data frame you are using, try doing something like this

ggplot(GWASRAW, aes(x = BASE_AGE1_R1, y = BIO_MTB_LIPID_CE_R1, color = BASE_SEX_R1))

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

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