我想在一些不相关的点之间画一条线。
这是我现在的代码:
probpostest %>%
filter(prev==15) %>%
mutate(
stat=replace(stat,stat=="prevalencia","Prevalencia"),
stat=replace(stat,stat=="probpostestpositivo","Probabilidad\nPostest\nPositivo"),
stat=replace(stat,stat=="probpostestnegativo","Probabilidad\nPostest\nNegativo"),
group=replace(group,group=="proven","Confirmada"),
group=replace(group,group=="proven_likely","Confirmada o\nprobable"),
group=replace(group,group=="proven_likely_possible","Confirmada,\nprobable o\nposible")) %>%
mutate(across(stat, factor, levels=c("Prevalencia","Probabilidad\nPostest\nPositivo","Probabilidad\nPostest\nNegativo")),
across(c(lower,upper), as.numeric),
lower=lower/100,
upper=upper/100) %>%
ggplot(aes(x=stat,
y=if_else(is.na(estimator*100),
100,
estimator*100),
ymin=lower,ymax=upper,color=stat)) +
geom_point() +
geom_text(aes(label=if_else(is.na(estimator),
"NC",
paste0(sprintf("%2.2f",estimator*100),"%")),
vjust=if_else(is.infinite(estimator),
1,
0.5),
hjust=-0.25),
show.legend = FALSE,
size=4) + # Esta línea quita la "a" de las leyendas
labs(x=NULL,y=NULL,title = "Figura 5. Probabilidades pre-test y post-test.",
caption="Prevalencia: probabilidad pre-test.\n\nProbabilidad pos-test positivo y negativo: probabilidad de tener candidiasis invasiva después de obtener un resultado positivo o negativo, respectivamente.\n\nNC: no calculable.")+
facet_grid(group ~ test,
scales = "free_y",
switch = "y"
) +
theme_minimal()+
theme(plot.title = element_text(hjust = 0.5),
plot.caption = element_text(hjust = 0),
legend.position = "none",
strip.text = element_text(face="bold")) +
scale_y_continuous(position = "right") +
scale_color_brewer(palette = "Set1")
我尝试添加geom_line(aes(x = stat, group=group)) +
,我可以得到这个,这不是我需要的。
我想知道如何将我感兴趣的点联系起来,然后在它们之间画一条线。谢谢您的帮助!
代表:
structure(list(prev = c(15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5,
5, 5), group = c("proven", "proven", "proven", "proven_likely",
"proven_likely", "proven_likely", "proven_likely_possible", "proven_likely_possible",
"proven_likely_possible", "proven", "proven", "proven", "proven_likely",
"proven_likely", "proven_likely", "proven_likely_possible", "proven_likely_possible",
"proven_likely_possible", "proven", "proven", "proven", "proven_likely",
"proven_likely", "proven_likely", "proven_likely_possible", "proven_likely_possible",
"proven_likely_possible", "proven", "proven", "proven", "proven",
"proven", "proven", "proven", "proven", "proven", "proven", "proven",
"proven", "proven", "proven", "proven", "proven", "proven", "proven"
), test = c("T2Candida", "T2Candida", "T2Candida", "T2Candida",
"T2Candida", "T2Candida", "T2Candida", "T2Candida", "T2Candida",
"Hemocultivo", "Hemocultivo", "Hemocultivo", "Hemocultivo", "Hemocultivo",
"Hemocultivo", "Hemocultivo", "Hemocultivo", "Hemocultivo", "T2Candida + Hemocultivo",
"T2Candida + Hemocultivo", "T2Candida + Hemocultivo", "T2Candida + Hemocultivo",
"T2Candida + Hemocultivo", "T2Candida + Hemocultivo", "T2Candida + Hemocultivo",
"T2Candida + Hemocultivo", "T2Candida + Hemocultivo", "T2Candida",
"T2Candida", "T2Candida", "Hemocultivo", "Hemocultivo", "Hemocultivo",
"T2Candida + Hemocultivo", "T2Candida + Hemocultivo", "T2Candida + Hemocultivo",
"T2Candida", "T2Candida", "T2Candida", "Hemocultivo", "Hemocultivo",
"Hemocultivo", "T2Candida + Hemocultivo", "T2Candida + Hemocultivo",
"T2Candida + Hemocultivo"), stat = c("prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo", "prevalencia", "probpostestpositivo",
"probpostestnegativo"), estimator = c(0.158, 0.635718612096565,
0.0361721611721612, 0.404, 0.637998056365403, 0.351610095735422,
0.561, 0.908822796377835, 0.472165444270771, 0.158, 1, 0.101195559350982,
0.404, 1, 0.351610095735422, 0.561, 1, 0.534908358936328, 0.158,
NA, 0.0184192119375146, 0.404, NA, 0.321802457897132, 0.561,
NA, 0.472165444270771, 0.1, 0.508196721311476, 0.0217391304347826,
0.1, 1, 0.0625, 0.1, NA, 0.010989010989011, 0.05, 0.328621908127209,
0.0104166666666667, 0.05, 1, 0.0306122448979592, 0.05, NA, 0.00523560209424084
), lower = c("7.5", NA, NA, "27.6", NA, NA, "42.4", NA, NA, "7.5",
NA, NA, "27.6", NA, NA, "42.4", NA, NA, "7.5", NA, NA, "27.6",
NA, NA, "42.4", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA), upper = c("27.9", NA, NA, "54.2",
NA, NA, "69.3", NA, NA, "27.9", NA, NA, "54.2", NA, NA, "69.3",
NA, NA, "27.9", NA, NA, "54.2", NA, NA, "69.3", NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
)), row.names = c(NA, -45L), class = c("tbl_df", "tbl", "data.frame"
))