如何用多行制作时间序列数据?

发布于 2025-01-25 03:44:46 字数 58 浏览 1 评论 0原文

我想及时地绘制甘蔗,椰子和大米的产量。但是我得到了这个输出:

![我的输出图] [1]

I want to plot the yield of sugarcane, coconut and rice in time. But I got this output:

![My output plot][1]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿嘿嘿 2025-02-01 03:44:46

您的数据应首先为汇总 d,因为它在同一日期和裁剪中具有多个条目,所以我假设您想要sum作为聚合功能。在数据参数中,我使用转换应用iSodate(请参阅其他答案)以及为绘图的pch color 定义数字向量。

a <- aggregate(Yield ~ ., 
               transform(data, Year=ISOdate(Year, 1, 1, 0),
                               clr=as.integer(factor(Crop)) + 1), FUN=sum) 

然后,绘图和空基地图,我建议log算术可能适合您的数据。接下来,使用的loop 在农作物上。最后,放置一个不错的传奇就是这样。

这里是一个基本版本:

plot(Yield ~ Year, a, log='y', type='n')
by(a, a$Crop, \(x) with(x, lines(Yield ~ Year, type='b', col=clr, pch=clr)))
legend('right', legend=unique(data$Crop), col=unique(a$clr), pch=unique(a$clr))

“在此处输入图像描述”

Your data should be aggregated first, since it has multiple entries for the same date and crop, I assume you want sum as aggregation function. In the data argument I use transform to apply ISOdate (see other answer) as well as define a numeric vector for pch and color for plotting.

a <- aggregate(Yield ~ ., 
               transform(data, Year=ISOdate(Year, 1, 1, 0),
                               clr=as.integer(factor(Crop)) + 1), FUN=sum) 

Then, plot and empty base plot, I suggest logarithmic might be suitable with you data. Next, loop lines over the crops using by. Finally place a nice legend that's it.

Here a basic version:

plot(Yield ~ Year, a, log='y', type='n')
by(a, a$Crop, \(x) with(x, lines(Yield ~ Year, type='b', col=clr, pch=clr)))
legend('right', legend=unique(data$Crop), col=unique(a$clr), pch=unique(a$clr))

enter image description here

惟欲睡 2025-02-01 03:44:46

ggplot(数据,aes(x =年,y =产量,颜色=作物,cop = crop)) + geom_smooth() + xlab(“”)

ggplot(data, aes(x = Year, y = Yield, colour = Crop, group = Crop)) + geom_smooth() + xlab("")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文