여기에서 수정 된 코드를 사용하여 내 문제를 설명하려고합니다 : 내 예에서 https://stats.stackexchange.com/questions/22805/how-to-draw-neat-polygons-around-scatterplot-regions-in-ggplot2ggplot2 및 boxplotdou의 그림을 결합하는 방법은 무엇입니까?
을, 나는 아이리스 데이터 세트를 사용합니다.
나의 시도는 지금까지 생산 한 :
내 목표는 (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)
나는 (... ggplot 내()는 boxplotdou을 삽입하려하지만 난이 오류가 발생했습니다 :. "플롯에 O를 추가하는 방법을 알고하지 마십시오"
어떤 도움을 주시면 감사하겠습니다.
-Kari
제발하지 마세요. – tchakravarty
나는 ggplot2에서이 모든 것을 시도해 보았습니다. 박스 플롯 바 및 상자의 상한값과 하한 값을 계산하는 두 번째 데이터 프레임을 만들어야합니다. 그런 다음 geom_rect를 사용하여 상자를 그립니다. 막대는 geom_errorbar로 그릴 수 있습니다. ggstance 패키지에서 geom_errorbarh가 필요할 수도 있습니다. https://github.com/lionel-/ggstance – timcdlucas