Consider a simple ggplot2 graph
library(ggplot2)
dat <- data.frame(name=c("apple", "orange", "plum"),value=c(3,8,2),outlier=c(FALSE,TRUE,FALSE))
ggplot(dat)+geom_point(aes(x=value,y=name))
Is there a way to modify styles attributes of the axis y labels (say color) conditionally, for example depending on the outlier
column in dat
?
The result would be something like
On a graph with a large number of items this feature wold greatly improve the graph readability and impact.
A simpler way (IMO) to do this is just create a conditional color vector and parse it into
axis.text.y
I don't think this is as good as colouring the outlier point itself, but you can hack away at the grob:
Doing this conditionally is possible using something like
c("grey50", "red")[dat$outlier]
assuming the row order is as needed. However, I can only reiterate that you probably should create a different graph if you think you need something like this.