Привет, я новичок и изо всех сил пытаюсь выяснить, как сделать пользовательские изменения цвета в моем блокпосте, используя ggplot2? Я хотел бы изменить самок на бордовый цвет, а самцов - на другой оттенок синего.
library(ggplot2)
plot.x <- ggplot(doubleboxplot) + geom_boxplot(aes(sex, x))
plot.y <- ggplot(doubleboxplot) + geom_boxplot(aes(sex, y))
plot.x <- layer_data(plot.x)[,1:21]
plot.y <- layer_data(plot.y)[,1:21]
colnames(plot.x) <- paste0("x.", gsub("y", "", colnames(plot.x)))
colnames(plot.y) <- paste0("y.", gsub("y", "", colnames(plot.y)))
df <- cbind(plot.x, plot.y); rm(plot.x, plot.y)
df$category <- sort(unique(doubleboxplot$sex))
df
library(dplyr)
library(data.table)
df.outliers <- df %>%
select(category, x.middle, x.outliers, y.middle, y.outliers) %>%
data.table::data.table()
df.outliers <- df.outliers[, list(x.outliers = unlist(x.outliers), y.outliers = unlist(y.outliers)),
by = list(category, x.middle, y.middle)]
df.outliers
p <- ggplot(df, aes(fill = category, color = category)) +
# 2D box defined by the Q1 & Q3 values in each dimension, with outline
geom_rect(aes(xmin = x.lower, xmax = x.upper, ymin = y.lower, ymax = y.upper), alpha = 0.3) +
geom_rect(aes(xmin = x.lower, xmax = x.upper, ymin = y.lower, ymax = y.upper),
color = "black", fill = NA) +
# whiskers for x-axis dimension with ends
geom_segment(aes(x = x.min, y = y.middle, xend = x.max, yend = y.middle)) + #whiskers
geom_segment(aes(x = x.min, y = y.lower, xend = x.min, yend = y.upper)) + #lower end
geom_segment(aes(x = x.max, y = y.lower, xend = x.max, yend = y.upper)) + #upper end
# whiskers for y-axis dimension with ends
geom_segment(aes(x = x.middle, y = y.min, xend = x.middle, yend = y.max)) + #whiskers
geom_segment(aes(x = x.lower, y = y.min, xend = x.upper, yend = y.min)) + #lower end
geom_segment(aes(x = x.lower, y = y.max, xend = x.upper, yend = y.max)) + #upper end
xlab("CD8 Activated") + ylab("CD8 CM") +
coord_cartesian(xlim = c(0.5, 11.5), ylim = c(0.5, 11.5)) +
theme_classic()
p + geom_point(doubleboxplot, mapping = aes(x = x, y = y, group = sex, color = sex), inherit.aes = F, alpha = 0.6)