Hi all!
I have a grouped boxplot and would like to add the sum of all these groups in an additional boxplot next to the grouped boxplots, to see if there is a big difference between the groups and all the data.
Here is my data:
library(dplyr)
library(tidyverse)
library(ggplot2)
gleich_entf_kat <- c(5,3,3,4,3,3,3,3,1,5,1,1)
gleich_entf_fakt <- c(1,3,0.5,0.7,3,2,2,0.5,0.1,1,10,15)
hh_wohnbdl <- c(3,2,2,1,3,2,2,2,1,2,3,1)
df <- data.frame(gleich_entf_kat,gleich_entf_fakt,hh_wohnbdl)
df %>%
drop_na(gleich_entf_kat, hh_wohnbdl, gleich_entf_fakt) %>%
ggplot(df, mapping = aes(
x = hh_wohnbdl,
y = gleich_entf_fakt
)) +
geom_boxplot(aes(group=hh_wohnbdl),size=2) +
# geom_boxplot(aes(group=sum(hh_wohnbdl)),size=2)+
geom_jitter(size=5, position=position_jitter(0.2),aes(color = factor(gleich_entf_kat)), alpha=0.6)+
scale_color_manual(values = c("red4", "red3", "orange", "green3", "green4"), labels = c("sehr schlecht", "schlecht", "mäßig", "gut", "sehr gut"),guide = guide_legend(shape = c(rep(16, 7), NA, NA),size=15)) +
scale_x_continuous(breaks = 1:3, name = "xyz", labels = c("A", "B", "C")) +
scale_fill_manual(breaks = 1:3, name = "xyz", labels = c("A", "B", "C")) +
labs(x = "xyz",
y = "kl [%]",
color = "kl:",size=50) +
theme_bw()+
theme(axis.text.x = element_text(size = 35),axis.title.x = element_text(size = 40),axis.text.y = element_text(size = 35),axis.title.y = element_text(size = 40),legend.title = element_text(size = 40),legend.text = element_text(size=35),legend.position = "bottom",legend.background = element_rect(color = "black",fill = "transparent"))
Here is my current plot, where I would like to add the summary of the groups on the right side:
I hope, I was clear enough in explaining my problem.
Yours,
Isabella