Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 按特定顺序连接点与几何图形线_R_Ggplot2 - Fatal编程技术网

R 按特定顺序连接点与几何图形线

R 按特定顺序连接点与几何图形线,r,ggplot2,R,Ggplot2,我试图使用ggplot根据一个因子连接点。但是,轨迹会沿着x轴移动。我应该怎么做来调整呢 dput(TimeEff) structure(list(Treat = c("N0", "N0", "N0", "N0+P", "N0+P", "N0+P", "N60", "N60", "N60", "N60+P", "N60+P", "N60+P", "N60+P+V", "N60+P+V", "N60+P+V", "N60+V", "N60+V", "N60+V"), Time = c("T15

我试图使用ggplot根据一个因子连接点。但是,轨迹会沿着x轴移动。我应该怎么做来调整呢

dput(TimeEff)
structure(list(Treat = c("N0", "N0", "N0", "N0+P", "N0+P", "N0+P", 
"N60", "N60", "N60", "N60+P", "N60+P", "N60+P", "N60+P+V", "N60+P+V", 
"N60+P+V", "N60+V", "N60+V", "N60+V"), Time = c("T157", "T217", 
"T7", "T157", "T217", "T7", "T157", "T217", "T7", "T157", "T217", 
"T7", "T157", "T217", "T7", "T157", "T217", "T7"), RS1 = c(-1.01597331415296, 
0.054728432606514, 1.23431053133827, -1.19280356432481, 1.61496198976957, 
0.636003270299734, -0.342528948667479, 0.194284721950614, 0.752617571838938, 
-0.0439584997550503, 0.369429998745985, -0.76081828888195, 1.12724878948647, 
-0.516440867545781, -1.70338001868143, 1.46801553741383, -1.7169642755269, 
-0.158733065913559), RS2 = c(1.75027373091837, -0.6927999472494, 
1.35360298097727, -1.63875683201727, 1.49686318476304, 0.472748817213433, 
0.324463226953492, -1.27828027422272, -1.38449342877724, -0.346570122181144, 
-0.587114634280834, -0.862512307254707, -0.14870885455771, -0.0765871299220654, 
0.983322157621319, 0.0592988508842657, 1.13791880091197, -0.56266821978008
)), class = "data.frame", row.names = c(NA, -18L))
这是ggplot函数:

TimeEff %>%
  mutate(Time = factor(Time, levels = c("T7", "T157", "T217"))) %>% 
  ggplot(aes(x = RS1, y = RS2, color = Treat))+
  geom_point(size=4)+
  geom_text(aes(label=Time),hjust=0, vjust=0)+
  geom_line(arrow = arrow(type = "closed"),size=1)
我希望每一组的线路都遵循T7->T157->T217的方向。我应该改变什么来解决这个问题


这就是你想要的吗

dplyr::arrange
根据设置的因子按时间变量对列进行排序,然后
ggplot::geom_path
按df中的行顺序连接点

       TimeEff %>%
          mutate(Time = factor(Time, levels = c("T7", "T157", "T217"))) %>% 
          dplyr::arrange(Time) %>%
          ggplot(aes(x = RS1, y = RS2, color = Treat))+
          geom_point(size=4)+
          geom_text(aes(label=Time),hjust=0, vjust=0)+
          geom_path(arrow = arrow(type = "closed"),size=1)

是否有办法在每个点上添加箭头,而不是只在最后添加箭头?