如何用多行制作时间序列数据?
我想及时地绘制甘蔗,椰子和大米的产量。但是我得到了这个输出:
![我的输出图] [1]
I want to plot the yield of sugarcane, coconut and rice in time. But I got this output:
![My output plot][1]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的数据应首先为
汇总
d,因为它在同一日期和裁剪中具有多个条目,所以我假设您想要sum
作为聚合功能。在数据参数中,我使用转换
应用iSodate
(请参阅其他答案)以及为绘图的pch
color 定义数字向量。然后,
绘图
和空基地图,我建议log
算术可能适合您的数据。接下来,使用的loop
行
在农作物上。最后,放置一个不错的传奇
就是这样。这里是一个基本版本:
Your data should be
aggregate
d first, since it has multiple entries for the same date and crop, I assume you wantsum
as aggregation function. In the data argument I usetransform
to applyISOdate
(see other answer) as well as define a numeric vector forpch
andcolor
for plotting.Then,
plot
and empty base plot, I suggestlog
arithmic might be suitable with you data. Next, looplines
over the crops usingby
. Finally place a nicelegend
that's it.Here a basic version:
ggplot(数据,aes(x =年,y =产量,颜色=作物,cop = crop)) + geom_smooth() + xlab(“”)
ggplot(data, aes(x = Year, y = Yield, colour = Crop, group = Crop)) + geom_smooth() + xlab("")