[R] Help for x axis

David L Carlson dcarlson at tamu.edu
Tue Nov 18 15:04:59 CET 2014


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