【发布时间】:2021-09-30 13:52:51
【问题描述】:
请在 R 中使用 ggplot 和 geom_line 命令绘制经验累积分布。 绘制的变量是三种高粱品种“soubatimi”、“tiandougou-coura”和“local”的产量,颜色分别为:绿色、蓝色和红色。但我无法在图表中添加相应颜色的图例. 这是输入(abc)
dput(abc)
structure(list(year = c(2018L, 2017L, 2020L), y_soubatimi = c(1614L,
1665L, 2181L), prob_soub = c(0.047619048, 0.083333333, 0.041666667
), cum_prob_s = c(0.047619048, 0.130952381, 0.172619048), year.1 = c(2018L,
2020L, 2017L), y_tiandougou_coura = c(1440L, 1475L, 1635L), prob_tc = c(0.047619048,
0.041666667, 0.083333333), cum_prob_tc = c(0.047619048, 0.089285714,
0.172619048), year.2 = c(2020L, 2018L, 2017L), y_local = c(916L,
945L, 1080L), prob_loc = c(0.041666667, 0.047619048, 0.083333333
), cum_prob_loc = c(0.041666667, 0.089285714, 0.172619048)), class = "data.frame", row.names = c(NA,
-3L))
ggplot()+geom_line(data=abc,aes(x=y_soubatimi),(stat="ecdf"),col="green")+
geom_line(data=abc,aes(x=y_tiandougou_coura),(stat="ecdf"),col="blue")+
geom_line(data=abc,aes(x=y_local),(stat="ecdf"),col="red")+
labs(x= "Yields,kg/ha",y = "Probability")+
scale_colour_discrete(name = "",
breaks= c("souba", "tiand", "loca"),
labels= c("y_soubatimi", "y_tiandougou_coura", "y_local")) +
theme_bw() +
theme(panel.grid.major.y = element_blank(),
axis.text.x = element_text(size=10),
axis.text.y = element_text(size=10),
legend.text =element_text(size=10))
【问题讨论】:
-
嘿,问题在于您绘制数据的方式。你能分享abc数据框吗?您可以执行 dput(abc) 并将结果粘贴到您的帖子中
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。