Dear RStudio Members,
I very much appreciate if anyone can give me some tip to how to removing data with missing values in geom_col. It took me hours to search various sources online. I tried the following methods:
But did not work. My data has 3 variables below:
- ID (103 participants): 1-103
- Dif_GAD7_0_9 (depression score, with 93 observations) which is simply a difference of pre- (week 0) and post-treatment (week 9) .
- Actual_Dif_GAD7_0_9 which represents reliable change or not (1=reliable change, 0=not reliable change, with 93 observations).
I used the following codes:
data2=data1[complete.cases(Dif_GAD7_0_9), ] data3<-data2[order(Dif_GAD7_0_9),] S1A_GAD0_9<-data3 %>% arrange(Dif_GAD7_0_9) %>% mutate(ID2=factor(ID, levels=ID)) %>% ggplot(aes(x = ID2, y = Dif_GAD7_0_9,fill = as.factor(Actual_Dif_GAD7_0_9))) + geom_col(position = "identity") + geom_hline(yintercept = 5.07) + scale_fill_manual(values = c("Red", "Green" ), labels = c('Not reliable change', 'Reliable change')) + theme_classic() + labs(x = "Individuals", y = "Total GAD-7 change", fill = "Actual_Dif_GAD7_0_9") + theme(axis.text.x = element_text(size = 5)) + annotate("text", x = 38, y = 10, label = " N=93\ Mean change=6.59\ SD=5.81", col = "Black", size = 2.5) + ggtitle("A. Week 9 vs week 0") + theme(plot.title = element_text(size = 8.5, face ="bold")) + theme(axis.title = element_text(size = 7.5, face ="bold")) + theme(legend.title = element_text(size = 7.5)) + theme(legend.text = element_text(size = 7.0)) + guides(color=c("Red", "Green")) + scale_fill_discrete(name="Reliable change", labels=c("Not reliable", "Reliable")) S1A_GAD0_9
And the output has been with a plot as attached
Rplot.pdf (6.4 KB)
The legend with NA still remains. So, I much acknowledge if anyone can help.
I look forward to receiving your support.