I was writing a code where I have to change certain lines in green color, or orange or red based on a certain criteria. it works fine when I have the data in code. But when it produces empty dataset then I have the problem. Just to give you a synopsis.
data_black_lines %>% ggplot(aes( date, cum, group = emp_code, text = paste("Name:", name) )) + geom_line(alpha = I(.05)) + geom_line( data = data_green_lines, color = I('green'), alpha = I(.10) ) + geom_line( data = , color = I('orange'), alpha = I(.2) , size = I(.5) ) + geom_line( data = data_red_lines, color = I('red'), alpha = I(.5) , size = I(.5) ) + geom_point(data = data_top_10, aes( date, cum, fill = I('steelblue') ), size=3, alpha=I(.4)) + geom_point(data = data_last_date, aes( date, cum, fill = I('royalblue') ), alpha=I(.12)) + geom_hline( yintercept = 50, color = 'red', size = I(.7), alpha = I(.7), linetype = 'dashed' ) + ylab('OverTime')
this is the code. and it produces this error.
Error: Aesthetics must be either length 1 or the same as the data (1): x, y, group, text
but data_orange_lines and data_red_lines are sometimes empty.
> data_orange_lines  emp_code date cum name <0 rows> (or 0-length row.names)
what should I do. It works fine if there is some data in the dataset but it doesn't work at all when the dataframe is empty....