【发布时间】:2023-03-27 08:49:01
【问题描述】:
很长一段时间以来,我都不希望在我的绘图 (ggplot2) 中拉直 x 轴的标签。 挑战在于我有两个 geom_paths,每个都从不同的数据帧中获取数据 - 我相信这在代码中会变得更加清晰:
ggplot(data=dx, aes(x = year, y=en.x ))+
scale_y_continuous(breaks = scales::pretty_breaks(n = 2))+
geom_path(data=ps, aes(x, y, color = "Person 1", linetype="Person 1"), size=0.5)+
geom_path(data=pg, aes(x , y, color = "Person 2", linetype="Person 2"), size=0.5)+
scale_color_manual("",labels = c(Nutzer1, Nutzer2), values = c("Person 1" = Nutzer1Farbe, "Person 2" = Nutzer2Farbe)) +
scale_linetype_manual("",labels = c(Nutzer1, Nutzer2), values=c("Person 1"=Nutzer1Format, "Person 2"=Nutzer2Format))
目标是用数据框“dx”中的年份标记 X 轴,如 aes 参数所示。它有效!但前提是您禁用 geom_paths - 如下所示:
ggplot(data=dx, aes(x = year, y=en.x ))+
scale_y_continuous(breaks = scales::pretty_breaks(n = 2))+
#geom_path(data=ps, aes(x, y, color = "Person 1", linetype="Person 1"), size=0.5)+
#geom_path(data=pg, aes(x , y, color = "Person 2", linetype="Person 2"), size=0.5)+
scale_color_manual("",labels = c(Nutzer1, Nutzer2), values = c("Person 1" = Nutzer1Farbe, "Person 2" = Nutzer2Farbe)) +
scale_linetype_manual("",labels = c(Nutzer1, Nutzer2), values=c("Person 1"=Nutzer1Format, "Person 2"=Nutzer2Format))
我真的不明白为什么路径会像这样破坏标签 - 它一定是 aes 参数。
如果有人对此有解决方案,我将非常感激!
【问题讨论】:
-
不知何故我没能成功运行
xspline(datengesamt[,2:2], shape=0.9, lwd=2, draw=F)。无论如何,尝试将您的年份设置为数字或日期格式