R 中的时间序列图,R 中的 y 轴不清楚
我编写了以下代码来按组绘制时间序列。
nsplot<- xyplot(conc ~ time |Location, data=nspm1long,
ylim=range(nspm1long$conc),
main="PM1 time series by Location",
ylab="PM1 concentration (mg/m3)",
xlab="Time", type="l",
par.strip.text=list(cex=0.7),
par.settings=list(axis.text=list(cex=0.7)))
print(nsplot)
我得到的是 y 轴的一块粗线,而不是像 x 轴那样的刻度线。有人可以帮我修复代码吗?如果我能控制 ylim 的范围(如 0-0.5)和刻度线的数量,那就更好了。
我不知道如何在此处附加图像,也许您也可以告诉我如何操作。
I wrote the following code to make time series plot by group.
nsplot<- xyplot(conc ~ time |Location, data=nspm1long,
ylim=range(nspm1long$conc),
main="PM1 time series by Location",
ylab="PM1 concentration (mg/m3)",
xlab="Time", type="l",
par.strip.text=list(cex=0.7),
par.settings=list(axis.text=list(cex=0.7)))
print(nsplot)
What I got is a block of thick line for the y-axis instead of the tickmarks like the x-axis. Would someone please help me fix the code. It would be even better if I could control the range of ylim like 0-0.5 and the number of tick marks.
I don't know how to attach the image here and perhaps you could show me how too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码的输出对我来说看起来不错。以下是我制作的一些示例数据得到的结果:
请参阅
?xyplot
获取所有绘图格式问题的答案,特别是scales
、tick.number
、ylim
、tck
参数。The output of your code looks fine for me. Here is what I get with some example data I made:
See
?xyplot
for the answers to all your plot formatting questions, specifically thescales
,tick.number
,ylim
,tck
parameters.使用了一段时间后,我了解到问题是由数据集中的 NA 值引起的。删除 NA 值后,绘图现在看起来不错。
约翰 - 谢谢你关于 ?xy 的提示。里面有很多很酷的东西。
Dirk - 我是 R 和时间序列数据操作的新手。我还不知道如何使用它,但会记住它
After playing with it for awhile, I learned the problem was caused by NA values in the dataset. After removing NA values, plot looks ok now.
John - Thank you for your tips about ?xy. There is a lot of cool stuff in there.
Dirk - I am new to R and time series data manipulation. I don't know how to use it yet but will keep it in mind