I have two df that I used for plotting.
df <- data.frame(x2=rnorm(100),y2=rnorm(100)) %>% mutate(Class=case_when(x2>0 ~1,
TRUE ~0))
df2<- structure(list(xpos = -2.5, ypos = -2, annotateText = structure(1L, .Label = "Text", class = "factor"),
hjustvar = 0, vjustvar = 0), class = "data.frame", row.names = c(NA,
-1L))
My plotting codes are:
ggplot(df, aes(x2, y2, colour=Class)) + geom_point()+
geom_text(data = df2, aes(x=xpos,y=ypos,hjust=hjustvar,
vjust=vjustvar,label=(annotateText)))
When I run it, I got error codes: Error in FUN(X[[i]], ...) : object 'Class' not found
. If I removed colour=Class
then my codes run. What did I do wrong? I really want to have the color difference for different groups. Any suggestion?