Automatic Highlighting Outliers in ggplots

I have a dataframe df. While plotting this in ggplot. Can we also highlight outliers. Below is the sample code

library(ggplot2)
df <- data.frame(col=runif(100, min=0, max=100000))
df$D <- c(1:100)
ggplot(df,aes(x=D,y=col))+geom_line()

Using the gghighlight package you can set whatever predicate you like for highlighting:

There are also examples of how to do this manually at the links below:

This one is for adding labels to certain points, but the principles are the same

2 Likes

Perfect and thanks a lot. For other users, below link I used to solve this problem

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.