I am trying to create a line chart that shows open symbols for data that is not detected and closed (filled) symbols to represent detected data. Here is the some code to work with:
date <- c("1991-04-25","1991-04-26","1991-04-27","1991-04-28","1991-04-29","1991-04-25","1991-04-26","1991-04-27","1991-04-28","1991-04-29","1991-04-25","1991-04-26","1991-04-27","1991-04-28","1991-04-29")
Parameter <- c("TEA","TEA","TEA","TEA","TEA","COFFEE","COFFEE","COFFEE","COFFEE","COFFEE","WATER","WATER","WATER","WATER","WATER")
data <- c(5,4,7,3,6,4,6,8,6,3,7,8,7,6,7)
DetectYN <- c("Y","N","Y","Y","Y","N","Y","Y","Y","N","N","N","Y","Y","N")
df <- data.frame(date, Parameter,data, DetectYN)
df$date <- as.Date(df$date, "%Y-%m-%d" )
df$DetectYN <-as.character(df$DetectYN)
ggplot(df, aes(x=date, y=data)) +
geom_point(size=4, aes(shape = Parameter , colour= Parameter)) +
geom_line(aes(x=date, y=data,color = Parameter)) +
scale_shape_manual(values=ifelse(DetectYN == "Y",c(15,16,17),c(0,1,2)) , guide = "none")
This creates the following chart - nearly correct, except that my ifelse is not having the desired effect. I would like the DetectYN = "N" to be hollow (no fill) and I would like the DetectYN = "Y" to be filled. The existing symbols need to remain. Could anyone help me with this please? 
This is a deceptively difficult problem! This solution directly answers your question, and is hopefully of some use. However, I fear that it may become messy with large, complicated datasets.
I added a column combining the two variables that you wish to control shape, and then defined shape by this new column, ordering the shape numbers to achieve the desired result.
df$shape<-paste(Parameter, DetectYN)
ggplot(df, aes(x=date, y=data, colour= Parameter)) +
geom_point(size=4, aes(shape=shape))+
geom_line() +
scale_shape_manual(values=c(0,15,1,16,2,17) , guide = "none")

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With