Я попытаюсь объяснить мою проблему с помощью модифицированного кода здесь: https://stats.stackexchange.com/questions/22805/how-to-draw-neat-polygons-around-scatterplot-regions-in-ggplot2Как совместить графики от ggplot2 и boxplotdou?
В моем примере, я использую набор данных Iris.
Мои попытки дали это до сих пор:
Моя цель состоит в том, чтобы построить Double Box Участок (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(), но я получил сообщение об ошибке: «Не знаю, как добавить о к сюжету»
Любая помощь будет оценен.
-Kari
Пожалуйста, не делайте этого. – tchakravarty
Я бы попытался сделать все это в ggplot2. Вам нужно будет создать второй фреймворк, в котором вы вычисляете значения для верхних и нижних значений для столбцов и ящиков boxplot. Затем постройте прямоугольники с geom_rect. Бары могут быть построены с помощью geom_errorbar. Может потребоваться geom_errorbarh из пакета ggstance. https://github.com/lionel-/ggstance – timcdlucas