ggplot2每组只包含一个观察

Sal*_*ali 20 r ggplot2

我试图使用ggplot2绘制图形

所以我有以下数据帧:

   iter        se perf name
1    V1 0.6463573 12.8    e
2    V2 0.3265986 16.8    e
3    V3 0.2333333 19.1    e
4    V4 0.1000000 19.9    e
5    V5 0.0000000 20.0    e
6    V1 0.7483315 12.6    f
7    V2 0.6333333 16.3    f
8    V3 0.6798693 18.8    f
9    V4 0.2236068 19.5    f
10   V5 0.1000000 19.9    f
Run Code Online (Sandbox Code Playgroud)

我试图以类似于此页面的格式绘制它(在线图下).

所以这是绘图的代码:

pd <- position_dodge(.1)
ggplot(df, aes(x=iter, y=perf, colour=name)) + 
  geom_errorbar(aes(ymin=perf-se, ymax=perf+se), width=.1, position=pd) +
  geom_line(position=pd) +
  geom_point(position=pd)+
  ylim(0, 20)
Run Code Online (Sandbox Code Playgroud)

它工作得很好: 在此输入图像描述,除了我想要连接这些点.我试图添加group=1或添加group=name到这部分,aes(x=iter, y=perf, colour=name)但它没有帮助.

我也收到这些警告:

ymax not defined: adjusting position using y instead
ymax not defined: adjusting position using y instead
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
Run Code Online (Sandbox Code Playgroud)

在互联网上查看后,我发现前两个是由于position_dodge,但我认为这是因为ggplot,第三个实际上是因为我的断点.

任何想法如何连接它们?

ags*_*udy 29

您需要调整组审美,替换:

   geom_line(position=pd) 
Run Code Online (Sandbox Code Playgroud)

通过

  geom_line(position=pd,aes(group=name))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Kir*_*n J 11

通过使用检查数据类型是否为因子is.factor(x),如果是TRUE,则使用as.integer函数.