开发者

Uneven axis in R plot

Is 开发者_JS百科it possible to draw an uneven axis in R? I know that I can specify labels at specific spots, but I mean, I want a particular section of my graph to be spread out. For instance, imagine an X axis such as:

-10 -5 0 1 2 3 4 5 10

where there is equal spacing between each of the above values.


You would need to make a factor of your levels, say "fac", and then plot. Later using axis() with labels=as.character(fac).

 dat <- data.frame(x=factor(c(-10 ,-5, 0, 1, 2, 3, 4, 5, 10)), y=1:9)

 with(dat, plot(x, y))   # a step-like plot
 with(dat, plot(as.numeric(x), y, type="p", xaxt="n")) # points instead of steps
 axis(1, at=1:9, labels=as.character(dat$x))           # the "irregular" axis

Thinking further about @Ben Bolker's question, it should also be possible to define a an auxiliary x-value to determine the plotting "x=" and the axis "at=" coordinate on the horizontal and then using unique(as.character(.)) applied to the "real x" as the "labels=" argument to axis as shown above but not needing a factor construction. An even more complex scheme is possible with this approach where continuous values across specific ranges of the auxiliary variable could be used for plotting but truncated values constructed for the labels at the boundaries of those ranges. I think further design justification and specification would be needed before building an implemented example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜