gpt4 book ai didi

r - 在 R 中的两个分类点之间添加一条虚线

转载 作者:行者123 更新时间:2023-12-02 02:43:27 28 4
gpt4 key购买 nike

我是 R 的新手,我已经编写了下面的交互图,为此我想要两条连接 "coral""darkgoldenrod2" 的虚线分别点:


df <- tibble::tribble(~Proportion, ~Lower,~Upper, ~Area,~Time,
invlogit(-0.033886), invlogit(-0.517223067), invlogit(0.449451067), "SNP", "Day",
(invlogit(-0.9231219)+invlogit(-0.3786)), 0.5727 ,0.8087, "SNP", "Night",
invlogit(-0.9231219), invlogit(-1.406458967), invlogit(-0.439784833),"LGCA", "Day",
invlogit(-0.1604356), invlogit(-0.643772667) ,invlogit(0.322901467), "LGCA","Night")
df


dfnew <- df %>%
mutate(ymin = Proportion - Lower,
ymax = Proportion + Upper)

p <- ggplot(data = dfnew, aes(x = Time, y = Proportion, color=Area)) +

geom_point(size = 6, stroke = 0, shape = 16,
position = position_dodge(width = 0.1))+
geom_errorbar(aes(y=Proportion, ymin = Lower, ymax = Upper),width=0.1,size=1,
position = position_dodge(width = 0.1)) +
theme(axis.text=element_text(size=15),
axis.title=element_text(size=20)) +
scale_color_manual(values = c("SNP" = "coral",
"LGCA" = "darkgoldenrod2"))
p

阅读其他关于 SO 的帖子,我使用了命令行:+geom_line(aes(group = 1),size=2)

然而,这并没有生成所需的图,如下所示:this

非常感谢您对此提供的任何帮助!

最佳答案

您应该将 group=Area 添加到您的 ggplot 映射中,然后您只需要调用 geom_line。您也不需要 geom_errorbar 中的 y=Position

p <- ggplot(data = dfnew, aes(x = Time, y = Proportion, color=Area, group=Area)) +
geom_point(size = 6, stroke = 0, shape = 16,
position = position_dodge(width = 0.1))+
geom_errorbar(aes(ymin = Lower, ymax = Upper), width=0.1, size=1,
position = position_dodge(width = 0.1)) +
theme(axis.text=element_text(size=15),
axis.title=element_text(size=20)) +
scale_color_manual(values = c("SNP" = "coral",
"LGCA" = "darkgoldenrod2")) +
geom_line(size=2)
p

Example

关于r - 在 R 中的两个分类点之间添加一条虚线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57592565/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com