简体   繁体   English

如何偏移 ax limited plot 上的第一个点,使其不在 R 的 y 轴上?

[英]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.

相关问题 如何在同一面板的同一X轴上绘制具有两个不同y轴范围的点? - How do I plot points with two different y-axis ranges on the same panel in the same X axis? 如何在 R 中标记 x & y 轴上的点的坐标 - How do I mark the coordinate of a point on x & y axis in R 如何更改 grouped_ggwithinstats() + dplyr ggplot 中第一个 plot 的 y 轴标签? - How do I change the y-axis labels of the first plot in a grouped_ggwithinstats() + dplyr ggplot? R - 如何绘制具有特定 y 轴(而不仅仅是频率)的直方图? - R - How do I plot a histogram with a specific y-axis (rather than just frequency)? y 轴上的名称和 x 轴上的值的 R 图 - R plot with names on the y-axis and values on the x-axis R图,x轴和y轴接触 - R plot, x-axis and y-axis touching Plot 日期在 x 轴和 y 轴“时间序列”R - Plot dates on x-axis and y-axis 'timeseries' R 除了R的默认图外,如何更改r中的x轴和y轴值? - How to change x-axis and y-axis value in r other than default plot by R? 如何通过R中的x值缩放直方图上的y轴? - How do I scale the y-axis on a histogram by the x values in R? 如何使用R中的绘图功能更改散点图中x轴和y轴标签的字体大小和颜色? - How to change the font size and color of x-axis and y-axis label in a scatterplot with plot function in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM