如何用不同的线形,形状和颜色来绘制一个趋势图?
我想观察FTSW的趋势。颜色由不同的集体区分,形状和线类型通过特征区分,如下图:
请参阅下面的原始数据:
df<-structure(list(Bloc = c(7, 7, 8, 8, 5, 5, 7, 7, 8, 8, 5, 5, 7,
7, 8, 8, 5, 5), Pos_heliaphen = c("W16", "W17", "W36", "W37",
"X02", "X03", "W16", "W17", "W36", "W37", "X02", "X03", "W16",
"W17", "W36", "W37", "X02", "X03"), traitement = c("WS", "WW",
"WW", "WS", "WS", "WW", "WS", "WW", "WW", "WS", "WS", "WW", "WS",
"WW", "WW", "WS", "WS", "WW"), Variete = c("Blancas", "Blancas",
"Blancas", "Blancas", "Blancas", "Blancas", "Blancas", "Blancas",
"Blancas", "Blancas", "Blancas", "Blancas", "Blancas", "Blancas",
"Blancas", "Blancas", "Blancas", "Blancas"), Date_obs = c("D07_27/05/2021",
"D07_27/05/2021", "D07_27/05/2021", "D07_27/05/2021", "D07_27/05/2021",
"D07_27/05/2021", "D12_07/06/2021", "D12_07/06/2021", "D12_07/06/2021",
"D12_07/06/2021", "D12_07/06/2021", "D12_07/06/2021", "D13_08/06/2021",
"D13_08/06/2021", "D13_08/06/2021", "D13_08/06/2021", "D13_08/06/2021",
"D13_08/06/2021"), FTSW_apres_arros = c(-0.82561716279966, -0.83052784248231,
-0.833812425397989, -0.826677385087996, -0.831991201718322, -0.827650244364889,
0.900083501645054, 0.899646933005172, 0.920126486265779, 0.901668054319428,
0.899616920453791, 0.899570142896103, -0.82561716279966, -0.83052784248231,
-0.833812425397989, -0.826677385087996, -0.831991201718322, -0.827650244364889
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-18L))
df %>%
select(1,2,3,4,5,6) %>%
ggplot(aes(Date_obs, FTSW_apres_arros),colour= Bloc,shape=traitement, linetype=traitement) +
geom_point() +
geom_line()+
labs(y=expression(paste('FTSW')))+
theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码的一个问题是,将
aes()
的闭合括号放在错误的位置,以便aes()()
中不包含颜色,形状和线型。另外,由于您的date_obs
列是您必须group
by Eg互动(BLOC,TRAITEMT)
以获取行绘图:您可以从数据集中创建标签向量
编辑 gude_legend(order = 1),以便首先出现颜色传说。
One issue with your code is that you put the closing parenthesis for
aes()
at the wrong position so that color, shape and linetype were not included inaes()
. Also, as yourDate_obs
column is a categorical you have togroup
by e.g.interaction(Bloc, traitement)
to get a line plot:EDIT You could create a vector of labels from your dataset which you could pass to
scale_color_discrete
like so:Note: I also added
guide = guide_legend(order = 1)
so that the color legend comes first.