library(ggplot2)
iris$Sepal.Length2 <- ifelse(iris$Sepal.Length < 5, 1, 0)
iris$Sepal.Width2 <- ifelse(iris$Sepal.Width < 3, 1, 0)
SmallLength <- data.frame(Petal.Length = iris$Petal.Length[iris$Sepal.Length2 == 1],
status = "Small Length")
LargeLength <- data.frame(Petal.Length = iris$Petal.Length[iris$Sepal.Length2 == 0],
status = "Large Length")
SmallWidth <- data.frame(Petal.Length = iris$Petal.Length[iris$Sepal.Width2 == 1],
status = "Small Width")
LargeWidth <- data.frame(Petal.Length = iris$Petal.Length[iris$Sepal.Width2 == 0],
status = "Large Width")
Length <- rbind(SmallLength, LargeLength)
Width <- rbind(SmallWidth, LargeWidth)
ggplot(Length, aes(Petal.Length, fill = status)) + geom_density(alpha = 0.2) + labs(x = "Petal Length")
I have a continuous variable, Petal.Length
, and I would like to stratify it by Sepal.Length
, and Sepal.Width
, both of which I have coded as binary variables. In the above plot, I stratified Petal.Length
by Sepal.Length
only. How can I further stratify it by Sepal.Width
? The resulting plot should perhaps have 4 colors I think...1 for Petal.Length
that have small length and small width, 1 for small length and large width, 1 for large length and small width, and 1 for large length and large width.