Hi All, I am in the annoying position of having to present some data to someone who seems to be somewhat less than numerate. I need to label the y-axes of a multhist with the y-axis labeled not as counts but as percentage of a population. Plotting the standard histogram is in a way fine, all I need is to: -- have a left-handside y-axis labels for pop 1 and a right-handside y-axis labels for pop2 -- replace the counts in each axis with population percentages (easy to calculate, but how to stick them there?) Any suggestion would be gratefully received. F -- Federico C. F. Calboli Department of Epidemiology and Biostatistics Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com
Please be more specific with your question. Perhaps a simple subset of the data you are trying to plot? Here is some non-specific advice: Plotting histograms as percentages instead of frequency counts is already an option of the hist function. For example, pop1<-rnorm(100) hist(pop1,freq=F) If you are plotting two histograms side-by-side (on the percentage scale), the y-axis of both plots can be set with the ylim option. For example, par(mfrow=c(1,2)) pop1<-rnorm(100) hist(pop1,freq=F,ylim=c(0,1)) pop2<-rgamma(100,1,1) hist(pop2,freq=F,ylim=c(0,1)) If your question were clearer, I might be able to help in more specific ways. -tgs On Fri, May 14, 2010 at 10:19 AM, Federico Calboli <f.calboli@imperial.ac.uk> wrote:> Hi All, > > I am in the annoying position of having to present some data to someone who > seems to be somewhat less than numerate. I need to label the y-axes of a > multhist with the y-axis labeled not as counts but as percentage of a > population. Plotting the standard histogram is in a way fine, all I need is > to: > > -- have a left-handside y-axis labels for pop 1 and a right-handside y-axis > labels for pop2 > -- replace the counts in each axis with population percentages (easy to > calculate, but how to stick them there?) > > Any suggestion would be gratefully received. > > F > > > -- > Federico C. F. Calboli > Department of Epidemiology and Biostatistics > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > > ______________________________________________ > R-help@r-project.org 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. >[[alternative HTML version deleted]]
On 05/15/2010 12:19 AM, Federico Calboli wrote:> Hi All, > > I am in the annoying position of having to present some data to someone who seems to be somewhat less than numerate. I need to label the y-axes of a multhist with the y-axis labeled not as counts but as percentage of a population. Plotting the standard histogram is in a way fine, all I need is to: > > -- have a left-handside y-axis labels for pop 1 and a right-handside y-axis labels for pop2 > -- replace the counts in each axis with population percentages (easy to calculate, but how to stick them there?) >Hi Federico, I may not have quite the right idea of what you want to do, but take a look at the last example for the barp function in the plotrix package. You seem to want the two ordinates because the positions of the percentages might be different? They won't be with barp used in that way, but you can add room for a right ordinate: par(mar=c(5,4,4,4)) and add axes with custom labels (assume that the total count is 50): axis(2,at=c(5,10,15,20),labels=c("10%","20%","30%","40%")) or you can use the height.at and height.lab arguments in barp. Jim