[英]How do I offset the first point on a x limited plot so its not on the y-axis in R?
I'm plotting data points by date using xyplot in R.我正在使用 R 中的 xyplot 按日期绘制数据点。 This was my initial code.
这是我的初始代码。
xyplot(data$SpainRo ~ data$Date, data= data)
I needed to plot the data from a certain point onward so I used this.我需要 plot 从某个点开始的数据,所以我使用了这个。
xyplot(data$SpainRo ~ data$Date, data-data, xlim=as.Date(c("2020-02-27","2020-05-13")))
It works however, the first data point for February 27th falls directly on the y-axis, getting obscured.但是,它有效,2 月 27 日的第一个数据点直接落在 y 轴上,变得模糊不清。 plot
plot
I was wondering how to move it to the right so the first point isn't on the y-axis.我想知道如何将它向右移动,以便第一个点不在 y 轴上。 Thank you for any help.
感谢您的任何帮助。
You need to exclude the data you don't want to plot, then expand the plot axis.需要排除不想要的数据plot,然后展开plot轴。
I'm assuming you are using xyplot
from the lattice
package.我假设您使用的是
lattice
xyplot
中的 xyplot。
lattice::xyplot(SpainRo ~ Date, data = data[data$Date > as.Date("2020-02-26"), ],
xlim = as.Date(c("2020-02-25","2020-05-13")))
Of course, I don't have your data
because you haven't shared it in your question, so can't demonstrate that this solution works.当然,我没有你的
data
,因为你没有在你的问题中分享它,所以不能证明这个解决方案有效。
Note that you don't need to include data$
before formula variables if the function takes a data
argument.请注意,如果 function 采用
data
参数,则不需要在公式变量之前包含data$
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.