[R] Fixing scale when plotting

Achim Zeileis zeileis at ci.tuwien.ac.at
Mon Feb 4 18:58:07 CET 2002


Jean Vidal wrote:
> 
> I would like to plot on the same page - with mfrow=c(2,5) - several
> barplots which describe answers to a question in a survey, ranging from 1
> to 10. Sometimes, values are not present in the dataset (nobody answers "1"
> to question A). To keep the graphs on the same scale, I tried, with little
> succes, to fix the scale, so that a level is represented even if no value
> is present.
> With an example :
> barplot(table(c(1,2,2,3,4,4,5)))
> barplot(table(c(2,2,2,4,4,4,5)))
> How to have the second plot on the same scale as the first, ranging from 1
> to 5, with all levels ?

You probably would want to keep the answer to the question as a factor
and not as a numeric vector:
  answer <- factor(c(2,2,2,4,4,4,5), levels=1:5)
  barplot(table(answer))

 
> Thanks for your help.
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list