[R] shading bar charts

Greg Snow Greg.Snow at intermountainmail.org
Fri Jun 29 20:11:34 CEST 2007


The first question you should ask yourself (and really think about the
answer) is "Why do I want to do this?"

Fancy colors and shadings can detract from a plot rather than enhance
it.  The wrong choice of colors can make bars look bigger or smaller
than they really are.  Reading Tufte's "The visual Display of
Quantitative Information" and Cleveland's "The Elements of Graphing
Data" explain many of these points.

The main graphics functions in R do not do things like this because the
underlying philosophy is that the data should speak for itself and not
need fancy chartjunk.  In fact, some of us on seeing fancy artistic
additions to graphs ask: "what are they trying to hide?".

If, after thinking this through and looking at your data plotted in a
basic chart, you decide that it is still justified to use shading, and
that it enhances the plot rather than detracts from it, then the
following shows one possible approach to doing something like your
example (you will need to modify to match your data):

> library(TeachingDemos)
>
> plot.new()
> plot.window( c(.5, 3.5), c(0,3.2), yaxs='i', xaxs='i')
> subplot( image( cbind( c(1:100,99:1) ), col=heat.colors(100),
axes=FALSE),
+ 	c(0.7,1.3), c(0,1) )
> subplot( image( cbind( c(1:100,99:1) ), col=heat.colors(100),
axes=FALSE),
+ 	c(1.7,2.3), c(0,3) )
> subplot( image( cbind( c(1:100,99:1) ), col=heat.colors(100),
axes=FALSE),
+ 	c(2.7,3.3), c(0,2) )
>
> axis(1, at=1:3, label=c("A","B","C") )
> axis(2, at=pretty(1:3, 2))
> box()

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> Federico Tomassini
> Sent: Friday, June 29, 2007 4:02 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] shading bar charts
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi alls,
> 
> i have to code a family of bar charts. After reading the doc, 
> i cannot understand if it is possible to shade the bar colors and how.
> 
> With shading i don't mean `density`. I mean something like that:
> 
> http://www.advsofteng.com/images/colorcylinder_g.png
> 
> 
> Thanks and br
> 
> - --
> Federico
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFGhNini7obm7aBjHcRAuvbAJ9y5lM+VoAGdko8hH2NQjrkSfvOlACfVDsT
> msphKZGSrswwnBGEssTv4nM=
> =aEwU
> -----END PGP SIGNATURE-----
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list