R ggplot2 在图中绘制多个时间序列
在成功(在您的帮助下)在单个(一个变量)图表中绘制气象变量之后,我尝试在单个面板中生成一个面板,其中包含数据中不同变量的时间序列,例如 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题是双重的。首先,熔化的
data.frame
中没有date
对象,它会向您提供错误消息。其次,您的FECHA.H_SOLAR
是一个难以正确绘制日期的因素。所以这是我的解决方案:希望它有帮助
the issue is twofold. First of all there's no
date
object within the melteddata.frame
, which gives you the error message. Second, yourFECHA.H_SOLAR
is a factor which would make hard plotting the dates correctely. So here is my solution:Hope it Helps