I have the following data frame
z = data.frame(x = seq(1,10),y = c(1,2,2,3,2,15,2,3,4,2))
To get a simple line plot is straight forward. For example this works.
p = ggplot() + geom_line(data=z,aes(x,y))
I now want to call out the fact that the data point with value 15 is an outlier. To do this, I would like to make the line connecting 5,2 to 6,15 and 7,2 dotted. Can this be done somehow in ggplot2?
You could make two lines, one dotted for all data, then one solid that excludes the outlier point. This seems to work:
ggplot() + geom_line(data=z,aes(x,y), linetype="dotted") + geom_line(data=z, aes(x, replace(y, y==15, NA)))
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