我想創建一個線圖,其形狀因Methods資料集中的變數而異。但是,我不希望在形狀上繪制線條,例如這不好:

如何隱藏形狀后面的線條,使線條不穿過形狀。這是資料集:
xx <- data.frame(
stringsAsFactors = FALSE,
rho = c(0.7,0.7,0.7,0.7,0.7,0.7,
0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,
0.7,0.7,0.7,0.7,0.7,0.7),
sample = c(1L,1L,1L,1L,1L,1L,1L,1L,
2L,2L,2L,2L,2L,2L,2L,2L,3L,3L,3L,3L,3L,3L,
3L,3L),
tp = c(10L,10L,10L,10L,20L,20L,
20L,20L,10L,10L,10L,10L,20L,20L,20L,20L,10L,10L,
10L,10L,20L,20L,20L,20L),
Methods = c("lmm","residualboot",
"clustboot","mbbboot","lmm","residualboot","clustboot",
"mbbboot","lmm","residualboot","clustboot","mbbboot",
"lmm","residualboot","clustboot","mbbboot","lmm",
"residualboot","clustboot","mbbboot","lmm","residualboot",
"clustboot","mbbboot"),
fixinterbias = c(-0.07069111,-0.08709062,
-0.13675904,-0.03077662,-0.2093937,-0.2092973,0.2344589,
-0.1650586,-0.08666544,-0.09681292,0.05795378,
-0.08564713,-0.015873476,-0.022712667,-0.090171359,
0.001930576,0.03720186,0.04073916,-0.08692844,0.04538355,
-0.09867106,-0.09874304,-0.08654507,-0.1161617),
fixslopebias = c(0.06225352,0.06467038,
0.06003106,0.05557157,-0.01036622,-0.01039492,-0.083628,
-0.01530608,0.02736118,0.02863767,0.04872466,0.02607667,
0.08056533,0.08076664,0.09773794,0.07819871,
-0.0703907,-0.07103784,-0.06005637,-0.07246422,0.0189303,
0.01863365,0.0145846,0.02057585)
)
這是我的代碼:
fixinter <- ggplot(xx, aes(x=sample, y=fixinterbias, shape=Methods, linetype=Methods))
geom_line(aes(color=Methods), size = 0.75)
geom_hline(yintercept=0, linetype="dashed", color = "black")
scale_shape_manual(values=c(0, 1, 2, 5))
scale_x_continuous(name="Sample size (n)", breaks = c(1, 2, 3), label = c(20, 50, 100))
scale_y_continuous(name="fix-effect intercept bias")
geom_point(aes(color=Methods, shape = Methods),
stroke = 1.0, fill = "white")
theme_classic()
fixinter facet_grid(tp ~. )
uj5u.com熱心網友回復:
您可以使用每個形狀的“填充”版本(例如ggpubr::show_point_shapes()用于查看串列),因此此處為 22、21、24 和 23。
fixinter <- ggplot(xx, aes(x=sample, y=fixinterbias, shape=Methods, linetype=Methods))
geom_line(aes(color=Methods), size = 0.75)
geom_hline(yintercept=0, linetype="dashed", color = "black")
scale_shape_manual(values=c(22, 21, 24, 23))
scale_x_continuous(name="Sample size (n)", breaks = c(1, 2, 3), label = c(20, 50, 100))
scale_y_continuous(name="fix-effect intercept bias")
geom_point(aes(color=Methods, shape = Methods),
stroke = 1.0, fill = "white")
theme_classic()
fixinter facet_grid(tp ~. )

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444201.html
上一篇:如何在ggplot中現場添加數值
