2016-06-05 3 views
1

Мне интересно, как предотвратить ablines на ggplot2 графике ниже от продолжения ниже 0 на оси х:сдерживающими в abline в ggplot2

fixef.c <- list(intercept0 = 1.72, slope0 = 0.04, intercept1 = 0.038, slope1 = -0.016) 

xy <- as.data.frame(rbind("White/Early Dropout" = c(intercept = fixef.c[[1]], slope = fixef.c[[2]]), 
          "White/Late Dropout" = c(intercept = fixef.c[[1]] + fixef.c[[3]]*3, slope = fixef.c[[2]]), 
          "Black/Early Dropout" = c(fixef.c[[1]], slope = fixef.c[[2]] + fixef.c[[4]]), 
          "Black/Late Dropout" = c(fixef.c[[1]] + fixef.c[[3]]*3, slope = fixef.c[[4]] + fixef.c[[2]]))) 

xy$design <- rownames(xy) 

ggplot() + 
    xlim(0, 12) + 
    ylim(1.6, 2.4) + 
    geom_abline(data = xy, aes(intercept = intercept, slope = slope, linetype = design, color = design)) + 
    scale_linetype_manual(values = c("White/Early Dropout" = "solid", "White/Late Dropout" = "dashed", "Black/Early Dropout" = "solid", "Black/Late Dropout" = "dotdash")) + 
    scale_color_manual(values = c("White/Early Dropout" = "black", "White/Late Dropout" = "black", "Black/Early Dropout" = "grey", "Black/Late Dropout" = "grey")) 

ответ

3

Я не думаю, что вы можете, но geom_segment может сделать работа довольно легко:

library(dplyr) 
xy <- xy %>% mutate(x=0, y=intercept, xend=12, yend=intercept+12*slope) 
ggplot() + 
    xlim(0, 12) + 
    ylim(1.6, 2.4) + 
    geom_segment(data = xy, aes(x=x, xend=xend, y=y, yend=yend, linetype = design, color = design)) + 
    scale_linetype_manual(values = c("White/Early Dropout" = "solid", "White/Late Dropout" = "dashed", "Black/Early Dropout" = "solid", "Black/Late Dropout" = "dotdash")) + 
    scale_color_manual(values = c("White/Early Dropout" = "black", "White/Late Dropout" = "black", "Black/Early Dropout" = "grey", "Black/Late Dropout" = "grey")) 

plot

Смежные вопросы