R - ggplot2 - 尽管数据单调,但取决于多个变量的图和 aes 会创建锯齿形

R - ggplot2 - plots and aes depending on multiple variables creates zigzag despite monotone data

根据年份和各种参数,我得到了 table 价格。

structure(list(Year = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 
3L, 4L, 1L, 2L, 3L, 4L), guar = c(0.01, 0.01, 0.01, 0.01, 0.02, 
0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 
0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 
0.01, 0.02, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 
0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02), 
vol = c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 
0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 
0.2, 0.2), fee = c(0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0.01, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0.01, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02), value = c(103.490219783939, 104.64694534429, 
105.423021866961, 106.003997632507, 103.987761167674,      105.637197779702, 
106.901255344043, 107.965567455406, 102.953065656004, 103.545441115507, 
103.741845779355, 103.732177003242, 103.490219783939, 104.64694534429, 
105.423021866961, 106.003997632507, 102.460474891754, 102.574796992078, 
102.307300703979, 101.84752143324, 103.036847936938, 103.785353707651, 
104.185436261084, 104.417467321901, 107.438302065026, 110.172519129122, 
112.120314291466, 113.657230720516, 107.965567455406, 111.246291601828, 
113.750976986408, 115.851941887821, 106.891292109859, 109.043467438409, 
110.389127553239, 111.309322271107, 107.438302065026, 110.172519129122, 
112.120314291466, 113.657230720516, 106.369273097772, 107.990957085228, 
108.806658224208, 109.200666959571, 106.935904609248, 109.17460141814, 
110.636502202272, 111.697991480364), rate = c(0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02)), row.names = c(NA, -48L
), class = "data.frame")

    Year guar vol  fee    value rate
 1     1 0.01 0.1 0.00 103.4902 0.02
 2     2 0.01 0.1 0.00 104.6469 0.02
 3     3 0.01 0.1 0.00 105.4230 0.02
 4     4 0.01 0.1 0.00 106.0040 0.02

并且现在想用 ggplot 以 "year" 为 x 轴,"value" 给出 y 值,颜色取决于 "guar", "vol" 上的形状,图形根据 "fee":

分为三个图表
 ggplot(df_tot,aes(x=Year,y=value,colour=as.factor(guar),shape=as.factor(vol)))+
   geom_line()+geom_point()+ facet_wrap(as.factor(fee))

然而,生成的图形呈锯齿状

尽管数据是单调的。例如,我们有

 > df_tot[df_tot$fee==0 & df_tot$guar==0.01 & df_tot$vol==0.1,5]
 [1] 103.4902 104.6469 105.4230 106.0040

我无法重现示例,出现错误。

我更改了 facet_wrap(~as.factor(fee)) 的构面并得到以下内容:

ggplot(df_tot,
       aes(x=Year,y=value,colour=as.factor(guar),shape=as.factor(vol)))+
  geom_line()+geom_point() + facet_wrap(as.factor(fee))