Существует более чем способ создания точечных диаграмм с маргинальными коробочными диаграммами.Я знаю как минимум 2: один с ggplot
и ggExtra
, а другой с пакетом car
:
ваши данные:
d1 <- read.table(header = TRUE, text =
"a1c att status
8.500000 23.58333 case
8.450000 12.25000 control
8.266667 18.91667 control")
ggplot и ggExtra
Если вы хотите использовать ggplot
Я считаю, вам нужно ggExtra
, чтобы сделать эту работу.Следующий код выполняет трюк
# load the packages
library(ggplot2)
library(ggExtra)
# make a usual ggplot and store it
# point size increased, legend to the bottom
p1 <- ggplot(d1, aes(x=a1c, y=att , color=status)) +
geom_point(size=2.5) +
theme(legend.position="bottom")
# marginal boxplot
# relative size of the central plot increased
ggMarginal(p1, type="boxplot", size=7)
, который приводит к этому графику (конечно, вы можете поиграть с темами и т. П.):
![enter image description here](https://i.stack.imgur.com/3fX2s.png)
Альтернатива: автомобильный пакет
library(car)
scatterplot(d1$a1c ~ d1$att | d1$status,
boxplots = "xy", regLine=FALSE, fill=d1$status, cex=2)
, что приводит к следующему графику:
![enter image description here](https://i.stack.imgur.com/3LDBf.png)