使用 ggplot 反映时间点之间的间距不均匀

Using ggplot to reflect uneven spacing between time points

提问人:Courtney 提问时间:11/11/2023 最后编辑:stefanCourtney 更新时间:11/11/2023 访问量:37

问:

我正在绘制纵向 trjaectories,这是生长混合物建模结果的潜在轨迹。我的数据是在分布不均匀的时间点收集的,比如年龄 13、15、17、21、24、27。我希望我的图表能够反映这种不均匀的分布,即“拉伸”更大的年龄差距。

我尝试使用scale_x_continuous,并确保扫描(时间点)是数字。在结果图中,标签是正确的,但彼此之间的距离仍然相等。

age <- c(13,15,17,21,24,27)
p  <- ggplot(long_dta, aes(Sweep, value, group=numericID, colour=gmm2_grp)) 
+ geom_line() + geom_smooth(aes(group= gmm2_grp), method="loess", size=2, se=F)  
+ scale_y_continuous(limits = c(0,40)) 
+ scale_x_continuous(labels = age) 
+ labs(x="Age(years)",y="total_score",colour="Latent Class") 

the x-axis with my current code

正如你所看到的,在 3 和 5、5 和 7 之间有 1 个“网格”,这是非常有意义的。但在这种情况下,在 7 和 11 之间应该有 3 个“网格”,依此类推。

我真诚地感谢任何关于如何反映我的情节中时间点分布不均的建议。

r ggplot2 时间序列 线-图 纵向

评论


答: 暂无答案