如何在x限制图上偏移第一个点,使其不在R的y轴上?

我正在使用R中的xyplot按日期绘制数据点。这是我的初始代码。

xyplot(data$SpainRo ~ data$Date, data= data)

我需要从某个点开始绘制数据,所以我使用了它。

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. plot

我想知道如何将其向右移动,以便第一个点不在y轴上。 感谢您的任何帮助。

评论
amodi
amodi

您需要排除不需要绘制的数据,然后展开绘制轴。

I'm assuming you are using xyplot from the lattice package.

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.

Note that you don't need to include data$ before formula variables if the function takes a data argument.

点赞
评论