ggplot 线条不穿过形状

ggplot lines not through shapes

我想创建一个线图,其形状因数据集中的 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 ~. )

您可以使用每个形状的“填充”版本(例如使用 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 ~. )