在ggplot(geom_line)上添加单个观测值

时间:2019-11-03 15:25:19

标签: r ggplot2

我具有以下数据框data frame,并且正在绘制每个级别的平均值(准确度)。但是我也希望在线上具有形状(例如Accuracy1,Accuracy2,Accuracy3等)的各个数据点。有人可以帮助我吗?谢谢

ggplot(data=Accuracy_means, aes(x=Effort_Level, y=Accuracy, 
                                group=1)) +
  geom_errorbar(aes(ymin=Accuracy-se, ymax=Accuracy+se), width=.05, size=1) +
  geom_line(size=1)+
  geom_hline(yintercept=c(-0.5,0.5), linetype="dashed", colour="black", size=0.5)+
  ylim(0,1)+
  coord_fixed(ratio = 2.5)+
  theme_classic()

1 个答案:

答案 0 :(得分:0)

尚不清楚是否要更改线型。如果是这样,这是一种使用gather中的tidyr的方法。

library(tidyverse)

Accuracy_means %>% 
  gather(key = accuracy_vars, value = values, -Effort_Level, -Accuracy, -se) %>% 
  ggplot(aes(x=Effort_Level,
             y=values)) +
  geom_errorbar(aes(ymin=Accuracy-se, ymax=Accuracy+se), colour = "red", width =0.05, size = 0.5) +
  geom_line(aes(linetype = accuracy_vars), size=1) +
  geom_line(aes(y = Accuracy), colour = "red")+
  coord_fixed(ratio = 2.5)+
  theme_classic()

enter image description here

相关问题