Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/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 使用带有POSIxct日期的geom_路径,使用ggplot2显示随时间变化的轨迹_R_Ggplot2_Tidyverse_Lubridate - Fatal编程技术网

R 使用带有POSIxct日期的geom_路径,使用ggplot2显示随时间变化的轨迹

R 使用带有POSIxct日期的geom_路径,使用ggplot2显示随时间变化的轨迹,r,ggplot2,tidyverse,lubridate,R,Ggplot2,Tidyverse,Lubridate,数据: 我想根据不同的处理方法使点的颜色不同,即使它们是分面的,但为了将日期转换为数字,我不得不放弃这一点。然而,该图仍然没有以正确的时间顺序显示轨迹。这可能是因为日期跨度在两年之间 所以最终我的问题是。如何让轨迹线跟随正确的日期序列中的点,同时也可能根据时间梯度给这条线着色 任何帮助都将不胜感激 这里有两个问题:1)geom_path按数据框中显示的顺序绘制数据,因此需要按时间顺序排序;2)seg3按日期分组,因此在取消分组之前很难按日期进行总体排序 ggplot(segs3, aes( x

数据:

我想根据不同的处理方法使点的颜色不同,即使它们是分面的,但为了将日期转换为数字,我不得不放弃这一点。然而,该图仍然没有以正确的时间顺序显示轨迹。这可能是因为日期跨度在两年之间

所以最终我的问题是。如何让轨迹线跟随正确的日期序列中的点,同时也可能根据时间梯度给这条线着色

任何帮助都将不胜感激

这里有两个问题:1)geom_path按数据框中显示的顺序绘制数据,因此需要按时间顺序排序;2)
seg3
按日期分组,因此在取消分组之前很难按日期进行总体排序

ggplot(segs3, aes( x = cnmds1, y = cnmds2)) +
  geom_point(size = 4) + 
  geom_path(aes(color = as.numeric(Date))) +
  geom_line(arrow = arrow()) +
  facet_wrap(~Treatment) + 
  coord_fixed() 

使用您提供的
df
返回问题的相同绘图?谢谢!!快速提问。你怎么知道tibble是按日期分组的?我记得使用group_by创建segs3,但如果给我这些数据,你怎么知道第一步是取消group?当我打印
segs3
时,输出是
\table:24 x 4;\分组:日期1[,3][12]
。(但首先,当我试图按日期安排时,它没有表现出来…)明白了!谢谢!
ggplot(segs3, aes( x = cnmds1, y = cnmds2)) +
  geom_point(size = 4) + 
  geom_path(aes(color = as.numeric(Date))) +
  geom_line(arrow = arrow()) +
  facet_wrap(~Treatment) + 
  coord_fixed() 
library(dplyr)
segs3 %>% 
  ungroup() %>%
  arrange(Date) %>%
ggplot(aes( x = cnmds1, y = cnmds2, color = Date)) +
  geom_point(size = 4) + 
  geom_path(arrow = arrow(type = "closed", 
                          length = unit(0.05, "npc"))) +
  facet_wrap(~Treatment) + 
  coord_fixed()