[R] Help for x axis

David L Carlson dcarlson at tamu.edu
Tue Nov 18 15:05:00 CET 2014


Try these:

aggData <- aggregate(age~smoke+gender, sampleData, function(x) c(mean=mean(x), 
	stderr=sd(x)/sqrt(length(x))))
aggData
plotInfo <- barplot(aggData$age[,1], ylim=c(0, max(rowSums(aggData$age))))
axis(1, c(0, plotInfo), c("Gender", "-", "-", "+", "+"), line=.75, 
	lwd=0, cex.axis=1.25, xpd=TRUE)
axis(1, c(0, plotInfo), c("Smoke", "-", "+", "-", "+"), line=2, 
	lwd=0, cex.axis=1.25, xpd=TRUE)
top <- aggData$age[,1]+aggData$age[,2]
bottom <- aggData$age[,1]-aggData$age[,2]
arrows(plotInfo, bottom, plotInfo, top, length=.15, angle=90, code=3)


boxplot(age~smoke+gender, sampleData, xaxt="n")
axis(1, 0:4, c("Gender", "-", "-", "+", "+"), line=.75, 
	lwd=0, cex.axis=1.25, xpd=TRUE)
axis(1, 0:4, c("Smoke", "-", "+", "-", "+"), line=2, 
	lwd=0, cex.axis=1.25, xpd=TRUE)


David

-----Original Message-----
From: Olivier [mailto:olivier.lerouzic at ymail.com] 
Sent: Monday, November 17, 2014 4:39 PM
To: David L Carlson
Subject: Re: [R] Help for x axis

Thank you very much, it is all I want to do. Is it possible with showing 
the error-bars or in a boxplot?
Best regards,

Olivier Le Rouzic

On 2014-11-17, 4:07 PM, David L Carlson wrote:
> This should get you started:
>
>> aggData <- aggregate(age~smoke+gender, sampleData, mean)
>> aggData
>    smoke gender      age
> 1     0      0 39.47231
> 2     1      0 40.09020
> 3     0      1 39.59814
> 4     1      1 42.04092
>> plotInfo <- barplot(aggData$age)
>> axis(1, c(0, plotInfo), c("Gender", "-", "-", "+", "+"), line=.75,
> + lwd=0, cex.axis=1.25, xpd=TRUE)
>> axis(1, c(0, plotInfo), c("Smoke", "-", "+", "-", "+"), line=2,
> + lwd=0, cex.axis=1.25, xpd=TRUE)
>
> To adapt it you will need to read the manual pages for barplot() and axis() and the page on graphical parameters par(). In particular, you will have to allocate more space at the bottom of the plot if you want to add more lines.
>
> -------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Olivier
> Sent: Monday, November 17, 2014 9:24 AM
> To: r-help at r-project.org
> Subject: [R] Help for x axis
>
> Hi,
> I want to customize x axis to scientific data. I do experiments with
> different triggers. As others publications, I want that there is one
> line for each trigger with the sign "-" or "+" to show if the trigger is
> used or no. You will find attached an exemple.
> Please find below a data.frame you could use to explain me.
> Thank you for your response,
> Olivier
>
>
>
> set.seed(3)
> sampleData <- data.frame(id = 1:100,gender = sample(c("0", "1"), 100,
> replace = TRUE), smoke = sample (c("0","1"), 100, replace=TRUE), age =
> rnorm(100, 40, 10))
> summary(sampleData)
>
> -> I want to give results with histograms or box.plot (age according to
> sex and smoking status)
> -> x axis may be like something like this :
>
> Gender        -          -         +        +
> Smoke         -          +        -         +
>
>



More information about the R-help mailing list