I attempt to create a line plot with data points using ggplot. I would like to assign the colour of points based on quartile based cut-off values. geom_point did not plot any points from summary statistics and issued a warning message "removed the rows containing missing values." The same code with numerical value explicitly included (not from summary statistics computation), the plots are nicely done. Appreciate if you could suggest the ways to fix the issue. The following is the reproducible code:
patient <- cbind.data.frame(seq(1:14),matrix(sample(1:100, 84), ncol=6))
colnames(patient) <- c('DAYS', 'PHYSICAL_ACTIVITY', 'SMOKING', 'ALCOHOL_INTAKE', 'HYDRATION', 'SLEEP', 'Total_score')
ggplot(data=patient, aes(x=DAYS,y=SLEEP)) +
geom_line(colour='black', size=1) +
geom_point(size=3,aes(colour=cut(SLEEP, c(-Inf,summary(SLEEP)[[2]],summary(SLEEP)[[5]],Inf))), show.legend=F) +
scale_color_manual(values = c("(-Inf,summary(SLEEP)[[2]]]" = "green", "(summary(SLEEP)[[2]],summary(SLEEP)[[5]]]" = "orange", "(summary(SLEEP)[[5]], Inf]" = "red")) +
theme(axis.title.y=element_blank()) +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(),axis.ticks.x=element_blank()) +
ggtitle("SLEEP (hrs)")+ theme(panel.background = element_blank()) +
guides(fill=FALSE)+ theme(plot.title = element_text(size = 8, face = "bold"))
Thanks