开发者

Improvements to the base R graphics

When I'm generating graphics for publications and talks, I tend to use ggplot2. However, for very large data sets where I want to generate a quick plot or for courses where students don't have a good grounding in R, I use the base graphics.

Are there any nice (simple!) ways of spicing up R graphics? For example, do you use a nice combination of colours and line types. I tend to do something like:

#Functional but not that nice    
plot(x1,y1, type="l")
lines(x2, y2, col=2, lty=2)

In particular, I'm thinking about the plot, hist, and density functions, but I suppose this question appli开发者_JAVA技巧es to all base R graphics.


Learn to use par. At the very least, make the y-axis label horizontal with par(las = 1). Manually adjusting margins with the mar and oma settings of par are also useful.

Use hue-chroma-luminance (HCL) colours, via the vcd package, especially for plots involving area (histograms or whatever).


The first half of Paul Murrell's R Graphics gives you advice on customising base graphics. If you want more general advice on drawing good graphs, Stephen Few's Now You See It is my personal favourite, and Edward Tufte's books are all staples.


As an alternative to teaching base graphics, you could use latticist to make lattice easier to learn.


I often skip position 3 in the default palette (green) because it generates dichromat-unfriendly plots. I should probably use palette(palette()[c(1:2,4:8,3)]) to do this automatically, but I tend to just do it by hand. I recommend the RColorBrewer package too.

Andrew Gelman (a pretty well-known statistician at Columbia with a very entertaining blog) would like you to adjust the margin and tick spacing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜