I'll try to explain my problem by using a modified code from here: https://stats.stackexchange.com/questions/22805/how-to-draw-neat-polygons-around-scatterplot-regions-in-ggplot2
In my example, I use the Iris data set.
My attempts have produced this so far:
My aim is to plot the Double Box Plot (boxplotdou) on the hulled scatter plot - with the same dimensions. The current code is:
library(ggplot2)
library(boxplotdbl)
df <- iris
find_hull <- function(df) df[chull(df$Sepal.Length, df$Sepal.Width), ]
hulls <- ddply(df, "Species", find_hull)
plot <- ggplot(data = df, aes(x = Sepal.Length, y = Sepal.Width, colour=Species, fill = Species)) +
geom_point() +
geom_polygon(data = hulls, alpha = 0.5) +
labs(x = "Sepal.Length", y = "Sepal.Width")
plot
par(new = TRUE)
# This is quite close what I'm trying to achieve, without axes. But it is in wrong position
#boxplotdou(Sepal.Length~Species, iris, Sepal.Width~Species, iris, factor.labels=FALSE, draw.legend=FALSE, name.on.axis=FALSE, ann = FALSE, axes = FALSE)
# This shows the axes, which do not match the underlying plot
boxplotdou(Sepal.Length~Species, iris, Sepal.Width~Species, iris, factor.labels=FALSE, draw.legend=FALSE, name.on.axis=FALSE, ann = FALSE)
I tried to insert the boxplotdou(... within ggplot() but I got an error: "Don't know how to add o to a plot".
Any help would be appreciated.
-Kari