# R 中分组箱线图中的颜色

##### 问题描述投票：0回答：1

r ggplot2 boxplot grouped-bar-chart
##### 1个回答
0

``alpha``

``````ggplot(df, aes(Race, Score, fill = Race, alpha = Sex,,
group = interaction(Sex, Race))) +
geom_boxplot(outlier.colour = NA) +
geom_point(size = 0.5, position = position_jitterdodge(0.1), alpha = 0.2) +
scale_fill_manual(NULL, values = c("deepskyblue", "purple", "red")) +
scale_y_continuous(limits = c(0, 6), expand = c(0, 0)) +
theme_minimal(base_size = 20) +
labs(x = NULL) +
scale_alpha_manual(values = c(0.5, 1)) +
guides(alpha = guide_legend(override.aes = list(fill = "gray"))) +
theme(panel.grid.major.x = element_blank())
``````

``interaction``

``````ggplot(df, aes(Race, Score, fill = interaction(Sex, Race, sep = " "),
group = interaction(Sex, Race))) +
geom_boxplot(alpha = 0.7, outlier.colour = NA) +
geom_point(size = 0.5, position = position_jitterdodge(0.1), alpha = 0.2) +
scale_fill_manual(NULL, values = c("deepskyblue3", "deepskyblue",
"purple3", "purple",
"red3", "red")) +
scale_y_continuous(limits = c(0, 6), expand = c(0, 0)) +
theme_minimal(base_size = 20) +
labs(x = NULL) +
theme(panel.grid.major.x = element_blank())
``````

``````ggplot(df, aes(Race, Score, fill = Sex, group = interaction(Sex, Race))) +
geom_boxplot(alpha = 0.5, outlier.colour = NA, width = 0.3,
position = position_dodge(0.5)) +
geom_point(size = 0.5, position = position_jitterdodge(0.05, 0, 0.5),
alpha = 0.2) +
scale_fill_manual(NULL, values = c("gold", "deepskyblue4")) +
scale_y_continuous(limits = c(0, 6), expand = c(0, 0)) +
theme_minimal(base_size = 20) +
labs(x = NULL) +
theme(panel.grid.major.x = element_blank(), legend.position = "top")
``````

© www.soinside.com 2019 - 2024. All rights reserved.