hi everyone, I would like to make a plot with an empty column in it. The reason that I still want to include this column in the R code is, I have multiple groups, with this column empty for some groups, but not for others. And the data of these groups are not available at the same time. I would like to make an R code for all these groups so that I do not need to change the code every time I obtain the data from a new group.
Here is an replicable example for one group with a column of missing data.
library(ggplot2)
mtcars$disp=NA
ggplot(mtcars)+
geom_line(data=mtcars[!is.na(mtcars$mpg),],aes(y=mpg,x=as.factor(carb),color='c1'))+geom_point(aes(y=mpg,x=as.factor(carb)))+
geom_line(data=mtcars[!is.na(mtcars$disp),],aes(y=disp,x=as.factor(carb),color='c2'))+geom_point(aes(y=disp,x=as.factor(carb)))+
geom_line(data=mtcars[!is.na(mtcars$qsec),],aes(y=qsec,x=as.factor(carb),color='c3'))+geom_point(aes(y=qsec,x=as.factor(carb)))+
scale_color_manual(values=c('c1'='red','c2'='yellow','c3'='blue'),labels=c('mpg','disp','qsec'))+
labs(x='carb',y='values',title='mtcars')
The error message is:
Aesthetics must be either length 1 or the same as the data (1): x and y
Run `rlang::last_error()` to see where the error occurred.
Is there any way I can still get the plot of the mpg and qsec (in one plot), even thought disp is fully missing?
Thank you very much.