[英]Reduce tick marks in xyplot in R
I have tried looking for the answer to this but none of the solutions have worked. 我试图寻找答案,但是没有一个解决方案。 I have created a plot with the following code:
我用以下代码创建了一个图:
library(lattice)
xyplot(Births.Registered..Number. ~ X, data=CSOStats, scales=list(
y=list(tick.number = 10)))
I have been able to change the tick marks for the y axis. 我已经能够更改y轴的刻度线。 I want to decrease the amount of tick marks for the x axis as well.
我也想减少x轴的刻度线数量。 The dates on the x axis are in this format "1960Q1", "1960Q2", etc. I have not been able to reduce the amount of ticks on the graph while maintaining the names of the respective tick.
x轴上的日期格式为“ 1960Q1”,“ 1960Q2”等。在保持各个刻度名称的同时,我无法减少图表上的刻度数量。 Ideally, I would be able to see a tick every 5 years (which is every 20 ticks), but I can't achieve this.
理想情况下,我可以每5年看到一个刻度(即每20个刻度),但我无法实现。 Here is a picture of the graph at present.
这是当前图表的图片。
tick.number
does not work for character
or factor
(from ?xyplot
): tick.number
不适用于character
或factor
(来自?xyplot
):
'tick.number' An integer, giving the suggested number of intervals between ticks.
'tick.number'一个整数,给出建议的刻度之间的间隔数。 This is ignored for a factor, shingle, or character vector, for in these cases there is no natural rule for leaving out some of the labels.
对于因数,带状疱疹或字符向量,将忽略此操作,因为在这种情况下,没有自然的规则来省略某些标签。
But you could use at
and labels
, eg: 但是你可以使用
at
和labels
,如:
library("lattice")
## example data
df <- data.frame(x=paste0(rep(1960:1999, each=4), paste0("Q", 1:4)), y=1:160)
## calculate position and create labels
x.tick.number <- 10
at <- seq(1, nrow(df), length.out=x.tick.number)
labels <- round(seq(1960, 1999, length.out=x.tick.number))
xyplot(y ~ x, data=df, scales=list(y=list(tick.number=10),
x=list(at=at, labels=labels, rot=90)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.