本文介绍了格子条形图的刻度标签不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试以格子形式创建条形图,但x轴刻度线未正确显示:
I am trying to create a bar chart in lattice but the x-axis tick marks are not showing correctly:
dd <- data.frame(Year = 1990:1999, Count = 0:9)
barchart(Count ~ Year, data = dd, horizontal = FALSE)
x轴的刻度标签应为1990、1991,...,而不是1、2.
The tick labels for the x-axis should be 1990, 1991, ... not 1, 2.
我不想在绘制之前将年份转换为因子,因为我需要使用latticeExtra
中的c.trellis( ..., x.same = TRUE)
将条形图与xyplot组合在一起,这似乎不适用于factor
轴.
I do not want to convert year to a factor before plotting because I need to combine the barchart with an xyplot using c.trellis( ..., x.same = TRUE)
in latticeExtra
, which does not seem to work with factor
axes.
我该如何解决?
推荐答案
您可以使用自定义的axis
函数:
You could use a custom axis
function:
barchart(Count ~ Year, data=dd, horizontal=FALSE,
axis=function(side, ...) {
if (side=="bottom")
panel.axis(at=seq_along(dd$Year), label=dd$Year, outside=TRUE, rot=0, tck=0)
else axis.default(side, ...)
})
这篇关于格子条形图的刻度标签不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!