R ggplot2 在图中绘制多个时间序列

发布于 2024-12-10 21:03:18 字数 1100 浏览 0 评论 0原文

在成功(在您的帮助下)在单个(一个变量)图表中绘制气象变量之后,我尝试在单个面板中生成一个面板,其中包含数据中不同变量的时间序列,例如 ggplot2 网页示例。我尝试用我的代码重现该示例(页面底部的最后一个图表)数据,但没有成功

我的数据跨度长达几年,但我只附上一个月。您可以在 http://ubuntuone.com/42j1RqUmNmxUuCppW4gElX 处查看 dput(datos) 的输出

,这是代码我正在尝试

datos=read.csv("paterna.dat",sep=";",header=T,na.strings="-99.9")
dm=melt(datos,id="FECHA.H_SOLAR")

datos$PRECIP[is.na(datos$PRECIP)]=0
dm=melt(datos,id="FECHA.H_SOLAR")
qplot(date, value, data = dm, geom = "line", group = variable) +  facet_grid(variable ~ ., scale = "free_y") 
Error: geom_line requires the following missing aesthetics: x
Además: Mensajes de aviso perdidos
1: In min(x) : ningún argumento finito para min; retornando Inf
2: In max(x) : ningun argumento finito para max; retornando -Inf

尝试 qplot,因为它出现在引用的示例中,但也许最好使用ggplot 并设置美学。然后我还可以自定义轴。

提前致谢

After succeeding (with your help) in plotting meteo variables in single (one variable) graphs I'm trying to produce a panel with time series of the different variables in my data in a single panel, like the one in ggplot2 webpage example. I have tried to reproduce that example (the last graph at bottom of the page) with my data but without success

My data span for several years but I attach just a month. You can see the output of dput(datos) at http://ubuntuone.com/42j1RqUmNmxUuCppW4gElX

and this is the code I'm trying

datos=read.csv("paterna.dat",sep=";",header=T,na.strings="-99.9")
dm=melt(datos,id="FECHA.H_SOLAR")

datos$PRECIP[is.na(datos$PRECIP)]=0
dm=melt(datos,id="FECHA.H_SOLAR")
qplot(date, value, data = dm, geom = "line", group = variable) +  facet_grid(variable ~ ., scale = "free_y") 
Error: geom_line requires the following missing aesthetics: x
Además: Mensajes de aviso perdidos
1: In min(x) : ningún argumento finito para min; retornando Inf
2: In max(x) : ningun argumento finito para max; retornando -Inf

I try qplot as it appears in the cited example but maybe it's better to use ggplot and set the aesthetics. Then I could also customize axes.

Thanks in advance

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

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

发布评论

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

评论(1

是伱的 2024-12-17 21:03:18

这个问题是双重的。首先,熔化的 data.frame 中没有 date 对象,它会向您提供错误消息。其次,您的 FECHA.H_SOLAR 是一个难以正确绘制日期的因素。所以这是我的解决方案:

datos <- source("http://ubuntuone.com/42j1RqUmNmxUuCppW4gElX")[[1]]
library(reshape2)
library(ggplot2)

datos$PRECIP[is.na(datos$PRECIP)] <- 0
dm <- melt(datos,id="FECHA.H_SOLAR")
# change FECHA.H_SOLAR to POSIXct so you get your dates right
dm$Fecha <- as.POSIXct(dm$FECHA.H_SOLAR, "%y/%m/%d %H:%M:%S", tz = "")
qplot(Fecha, value, data = dm, geom = "line", group = variable) +
  facet_grid(variable ~ ., scale = "free_y")

在此处输入图像描述

希望它有帮助

the issue is twofold. First of all there's no date object within the melted data.frame, which gives you the error message. Second, your FECHA.H_SOLAR is a factor which would make hard plotting the dates correctely. So here is my solution:

datos <- source("http://ubuntuone.com/42j1RqUmNmxUuCppW4gElX")[[1]]
library(reshape2)
library(ggplot2)

datos$PRECIP[is.na(datos$PRECIP)] <- 0
dm <- melt(datos,id="FECHA.H_SOLAR")
# change FECHA.H_SOLAR to POSIXct so you get your dates right
dm$Fecha <- as.POSIXct(dm$FECHA.H_SOLAR, "%y/%m/%d %H:%M:%S", tz = "")
qplot(Fecha, value, data = dm, geom = "line", group = variable) +
  facet_grid(variable ~ ., scale = "free_y")

enter image description here

Hope it Helps

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