我有一个方框图,显示干预前后的分数。我想点几个不同颜色的点,基于另一个分数。
换句话说,假设10名受试者在干预前的得分为(8,9,10,8,9,10,8,9,10,8,10,8),干预后的得分为(12,9,12,8,9,10,9,10,10,10)。现在,使用标准的ggplot盒子图,我将组1和组2显示为具有不同颜色的盒子图。
PreopRespondersBoxPlotLDS <- ggboxplot(data=PreopResponders,
x="Response",y="RespondersVsNonPreopLDS.preop", color = "Response", palette =
"jco", add = "jitter") + labs(title = "Left Dorsal Striatum Connectivity to the Right Occipital Cortex", y = "Connectivity")
+ theme(axis.title.x = element_blank(), legend.position="none", legend.title = element_blank(), plot.title = element_text(hjust = 0.5))我没有收到错误消息,我只是希望能够使用额外的颜色来编写二进制变量的代码。
发布于 2019-06-19 02:57:38
以下是问题所要求的内容。它使用geom_boxplot,而不是ggboxplot。并通过对geom_jitter的调用中的二进制条件对数据进行子集。此条件很容易成为二进制数据帧变量。
另请注意,我在图形标题中包含了换行符"\n"。
library(ggplot2)
g <- ggplot(PreopResponders, aes(x = Response, y = RespondersVsNonPreopLDS.preop,
color = Response)) +
geom_boxplot() +
geom_jitter(data = subset(PreopResponders, Age > 50),
color = "black",
width = 0.25, height = 0.25) +
labs(title = "Left Dorsal Striatum Connectivity \nto the Right Occipital Cortex", y = "Connectivity") +
theme(axis.title.x = element_blank(),
legend.position = "none",
legend.title = element_blank(),
plot.title = element_text(hjust = 0.5))
g

数据创建代码。
PreopResponders <- data.frame(Response = factor(rep(c("Before", "After"), each = 10), labels = c("Before", "After")),
RespondersVsNonPreopLDS.preop = c(c(8,9,10,8,9,10,8,9,10,8),
c(12,9,12,8,9,10,10,9,10,10)))
set.seed(1234)
PreopResponders$Age <- sample(18:100, 20, TRUE)https://stackoverflow.com/questions/56654984
复制相似问题