如何使用2种条件为点着色?

时间:2019-03-29 00:47:49

标签: r ggplot2 scatter

我希望根据散点图中的点是否符合我的Depo标准来对其进行着色。我尝试用Cutoff着色并为Depo使用形状,但这并没有给我带来视觉效果。我真的希望只有在Cutoff和所有Depo都为黑色的地方,才用Cutoff = Good/Maybe上色。

Cutoff = Bad

我尝试过此方法,但不会使不良样品脱颖而出

Depth    Pj         T         Depo    Cutoff
100.69    1.095802    0.9986513    Dri    Good
97.04    1.009357    0.9624445    Pro    Good
74.74    1.039274    0.9880176    Tur    Maybe
106.46    1.054291    0.9873374    Pro    Maybe
109.37    1.117034    0.9913281    Dri    Bad
90.29    1.01166        0.9107071    Pro    Bad

1 个答案:

答案 0 :(得分:0)

这样的事情怎么办?

df %>%
    mutate(col = factor(ifelse(
        Cutoff %in% c("Good", "Maybe"),
        as.character(Depo),
        NA))) %>%
    ggplot(aes(x = Pj, y = T, colour = col, shape = Cutoff)) +
    geom_point()

enter image description here


样本数据

df <- read.table(text = "Depth    Pj         T         Depo    Cutoff
100.69    1.095802    0.9986513    Dri    Good
97.04    1.009357    0.9624445    Pro    Good
74.74    1.039274    0.9880176    Tur    Maybe
106.46    1.054291    0.9873374    Pro    Maybe
109.37    1.117034    0.9913281    Dri    Bad
90.29    1.01166        0.9107071    Pro    Bad", header = T)