我将尝试使用此处的修改代码来解释我的问题: https://stats.stackexchange.com/questions/22805/how-to-draw-neat-polygons-around-scatterplot-regions-in-ggplot2
在我的例子中,我使用了Iris数据集。
到目前为止,我的尝试产生了这个:
我的目标是在带壳散点图上绘制 Double Box Plot (boxplotdou) - 具有相同的尺寸。目前的代码是:
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)
我试图插入boxplotdou(...在ggplot()中但是我收到了一个错误:&#34;不知道如何将o添加到情节&#34;。
任何帮助都将不胜感激。
-Kari