英文:
Plot factors side by side in ggplot2
问题
我有如下表格,并想制作一个散点图,其中每个因子的点都是并列的。这是否可能?
数据:
fishers.drugs %>%
ggplot(aes(fill = Method, color = Method, x = Phenotype, y = OR, ymin = Lower.CI, ymax = Upper.CI)) +
geom_errorbar(aes(color = Method), show.legend = FALSE) +
geom_point(shape = 21, size = 12) +
scale_fill_manual(values = c("yellow", "cyan4")) +
scale_color_manual(values = c("black", "black")) +
theme_bw(base_size = 20) +
theme(text = element_text(size = 34), axis.text.x = element_text(hjust = 1))
你的代码看起来已经设置得很好,但要确保你的数据集已正确加载。
英文:
I have a table as shown below, and I would like to make a scatterplot whereby the points for each factor is side by side instead. Is that possible?
fishers.drugs %>%
ggplot(aes(fill = Method, color=Method, x=Phenotype, y=OR, ymin = Lower.CI, ymax = Upper.CI)) +
geom_errorbar(aes(color=Method), show.legend = FALSE)+
geom_point(shape=21, size=12) +
scale_fill_manual(values = c("yellow", "cyan4"))+
scale_color_manual(values = c("black","black"))+
theme_bw(base_size = 20) +
theme(text=element_text(size=34),axis.text.x = element_text(hjust = 1))
Data:
fishers.drugs <- structure(list(Phenotype = c("SCZ", "BD", "MDD", "PTSD", "SCZ",
"BD", "MDD", "PTSD"), P.value = c(3.6e-05, 7.6e-06, 0.0023, 0.03,
0.29, 0.043, 0.19, 0.71), Method = c("Pairwise", "Pairwise",
"Pairwise", "Pairwise", "MAGMA", "MAGMA", "MAGMA", "MAGMA"),
OR = c(3.1, 3.7, 2.53996, 2.6, 1.27, 1.9, 1.574722, 0.8),
Lower.CI = c(1.80232, 2.124302, 1.352569, 0.9064928, 0.5729662,
0.9067536, 0.7052697, 0.09566171), Upper.CI = c(4.846504,
6.090133, 4.40825, 5.8462159, 2.4825332, 3.6740963, 3.0758353,
3.01399383)), class = "data.frame", row.names = c(NA, -8L
))
答案1
得分: 2
这是您所想要的吗?我已经更改了两个点和误差条的位置。
library(ggplot2)
library(dplyr)
fishers.drugs %>%
ggplot(aes(fill = Method, color=Method, x=Phenotype, y=OR, ymin = Lower.CI, ymax = Upper.CI)) +
geom_errorbar(aes(color=Method), show.legend = FALSE, position = position_dodge(width = 1))+
geom_point(shape=21, size=12, position = position_dodge(width = 1)) +
scale_fill_manual(values = c("yellow", "cyan4"))+
scale_color_manual(values = c("black","black"))+
theme_bw(base_size = 20) +
theme(text=element_text(size=34),axis.text.x = element_text(hjust = 1))
Created on 2023-04-06 with reprex v2.0.2
英文:
Is this what you are picturing? I've changed positions for both points and error bars.
library(ggplot2)
library(dplyr)
fishers.drugs %>%
ggplot(aes(fill = Method, color=Method, x=Phenotype, y=OR, ymin = Lower.CI, ymax = Upper.CI)) +
geom_errorbar(aes(color=Method), show.legend = FALSE, position = position_dodge(width = 1))+
geom_point(shape=21, size=12, position = position_dodge(width = 1)) +
scale_fill_manual(values = c("yellow", "cyan4"))+
scale_color_manual(values = c("black","black"))+
theme_bw(base_size = 20) +
theme(text=element_text(size=34),axis.text.x = element_text(hjust = 1))
<!-- -->
<sup>Created on 2023-04-06 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论