根据条件比较三列,与小平面绘制点

时间:2016-09-21 18:45:33

标签: r

我的数据如下

  datas=structure(list(RT_theorique = structure(c(18L, 28L, 36L, 42L, 
        50L, 5L, 13L, 23L, 33L, 40L, 46L, 37L, 43L, 47L), .Label = c("17:03:55", 
        "17:06:24", "17:08:53", "17:11:30", "17:13:57", "17:17:49", "17:25:01", 
        "17:34:49", "17:37:18", "17:41:10", "17:43:02", "17:45:27", "17:46:33", 
        "17:48:55", "17:51:09", "17:53:36", "17:56:45", "17:59:34", "18:03:13", 
        "18:05:52", "18:09:44", "18:11:49", "18:14:45", "18:18:01", "18:20:48", 
        "18:23:55", "18:26:47", "18:31:34", "18:34:42", "18:36:32", "18:38:32", 
        "18:41:57", "18:44:33", "18:47:57", "18:51:21", "18:59:16", "19:05:46", 
        "19:07:55", "19:11:24", "19:15:13", "19:25:35", "19:29:09", "19:33:02", 
        "19:36:08", "19:41:06", "19:44:31", "19:49:21", "19:53:43", "19:56:05", 
        "19:59:56"), class = "factor"), Result_theorique = c("E", "E", 
        "F", "F", "F", "E", "F", "F", "F", "F", "F", "E", "E", "E"), 
            RT_real = structure(c(19L, 29L, 38L, 47L, 54L, 5L, 14L, 
            24L, 34L, 42L, 51L, 39L, 48L, 52L), .Label = c("17:03:13", 
            "17:05:44", "17:08:44", "17:11:39", "17:14:39", "17:18:06", 
            "17:21:13", "17:24:02", "17:27:05", "17:32:43", "17:35:59", 
            "17:38:40", "17:41:26", "17:44:43", "17:48:14", "17:51:14", 
            "17:55:00", "17:57:16", "18:00:12", "18:03:16", "18:06:03", 
            "18:09:59", "18:12:49", "18:15:37", "18:18:01", "18:21:31", 
            "18:26:09", "18:27:58", "18:29:52", "18:33:21", "18:36:40", 
            "18:38:50", "18:41:25", "18:44:35", "18:48:45", "18:52:08", 
            "18:54:19", "18:59:52", "19:02:28", "19:06:04", "19:11:18", 
            "19:15:03", "19:18:06", "19:21:37", "19:25:37", "19:28:26", 
            "19:30:22", "19:33:31", "19:36:16", "19:41:00", "19:45:15", 
            "19:52:00", "19:53:56", "19:59:58"), class = "factor"), Result_real = c("E", 
            "E", "F", "F", "E", "F", "F", "F", "F", "F", "F", "E", "E", 
            "E"), Experiment_code = structure(c(11L, 11L, 11L, 11L, 11L, 10L, 
            10L, 10L, 10L, 10L, 10L, 8L, 8L, 8L), .Label = c("#N/A", 
            "Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6", "Exp7", "Exp8", 
            "Exp9", "Exp10"), class = "factor"), Concordance = c("OUI", 
            "OUI", "OUI", "OUI", "NON", "NON", "OUI", "OUI", "OUI", "OUI", 
            "OUI", "OUI", "OUI", "OUI")), .Names = c("RT_theorique", 
        "Result_theorique", "RT_real", "Result_real", "Experiment_code", "Concordance"
        ), row.names = c(2L, 3L, 4L, 5L, 6L, 24L, 25L, 26L, 27L, 28L, 
        29L, 21L, 22L, 23L), class = "data.frame")

我进行了实验,Result_theorique表示预测结果和Result_real以及由Experiment_code编码的实验的实际结果。如果Result_theorique符合Result_real,则concordance将为oui,否则为non

我希望根据两条规则进行以下表示:

如果concordanceoui,我想用蓝色圆点代表它。 如果concordancenon,我想用红点代表Result_theorique,用黑点代表Result_real

在X轴上它将是RT_theorique(反应时间理论)

enter image description here

我已经为每个Experiment_code

尝试了以下代码
up_th  <- ggplot(datas, aes(RT_theorique,Result_real, fill=Concordance)) + geom_point() +facet_wrap("Experiment_code")+
   ggtitle("Mission par heure") +
   theme_bw() +
   theme(plot.title = element_text(size=16,lineheight=2, face="bold"),
   legend.text=element_text(size=12),
   legend.title=element_text(size=12, face="bold"),
   axis.text.y = element_text(size=12),
   axis.text.x = element_text(size=6, angle=45, hjust=1, vjust=1),
   strip.background = element_rect(fill = "White"))  

我不知道如何指定点的颜色? 非常感谢

1 个答案:

答案 0 :(得分:1)

这个怎么样?

ggplot(datas, aes(RT_theorique,Result_real, col=Concordance)) + 
  geom_point(size=5) +
  facet_wrap("Experiment_code")+
  ggtitle("Mission par heure") +
  scale_color_manual(values=c('black', 'blue')) +
  theme_bw() +
  theme(plot.title = element_text(size=16,lineheight=2, face="bold"),
        legend.text=element_text(size=12),
        legend.title=element_text(size=12, face="bold"),
        axis.text.y = element_text(size=12),
        axis.text.x = element_text(size=6, angle=45, hjust=1, vjust=1),
        strip.background = element_rect(fill = "White"))  

enter image description here

ggplot(datas, aes(RT_theorique,Result_theorique, col=Concordance)) + 
  geom_point(size=5) +facet_wrap("Experiment_code")+
  ggtitle("Mission par heure") +
  scale_color_manual(values=c('red', 'blue')) +
  theme_bw() +
  theme(plot.title = element_text(size=16,lineheight=2, face="bold"),
        legend.text=element_text(size=12),
        legend.title=element_text(size=12, face="bold"),
        axis.text.y = element_text(size=12),
        axis.text.x = element_text(size=6, angle=45, hjust=1, vjust=1),
        strip.background = element_rect(fill = "White"))