Using the Iris data set as an example, I can produce a ggplot with facet. The code is:
library(ggplot2)
data(iris)
y=iris
y$Petal.Width.Range=factor(ifelse(y$Petal.Width<1.3,"Narrow","Wide"))
y$Petal.Length.Range=factor(ifelse(y$Petal.Length<4.35,"Short","Long"))
ggplot(y, aes(Sepal.Length,Sepal.Width)) +
geom_point(alpha=0.5)+
geom_hline(yintercept =3 ,alpha=0.3)+
facet_grid(Petal.Width.Range ~ Petal.Length.Range)
Here I have a horizontal spec of 3 in each of the 4 cases. What should I do if I want a case dependent spec please? For example, I can define 4 different specs as the following:
y$threshold=2
y$threshold[(y$Petal.Width.Range=="Narrow")&(y$Petal.Length.Range=="Short")] =2
y$threshold[(y$Petal.Width.Range=="Narrow")&(y$Petal.Length.Range=="Long")] =2.5
y$threshold[(y$Petal.Width.Range=="Wide")&(y$Petal.Length.Range=="Short")] =3.1
y$threshold[(y$Petal.Width.Range=="Wide")&(y$Petal.Length.Range=="Long")] =4
How should I add y$threshold into the ggplot commands please?