On Jun 21, 2011, at 4:29 PM, Adrienne Keller wrote:
I am making a barplot using barplot2 from gplots where each bar
represents a specific tree species. I have formatted the species
names on the x-axis so that the genus name is above the species name
and have then rotated the labels 45 degrees to save room. This is my
code:
>columncolor<-c("grey20", "grey20", "grey20", "grey70", "grey70",
"grey70", "grey70", "grey70", "grey70")
>speciesnames<-c("Dialium\nguianensis", "Inga\nalba", "Tachigali
\nversicolor", "Brosimum\nutile", "Caryocar\ncostaricense", "Castilla
\ntunu", "Otoba\nnovagranatensis", "Pourouma\nbicolor", "Socratea
\nexorrhiza")
>barplot2(meanapAprilactivity, names.arg=speciesnames,
col=columncolor, xlab="Species", ylab="Soil acid phosphatase
activity (nmol/h/g)", ylim=c(0,1000), plot.ci=T,
ci.l=apAprilminusordered, ci.u=apAprilplusordered,
cex.lab=1.5)#FinalGraphs>aPApril_Genus.pdf
... "object 'meanapAprilactivity' not found"
>xvals<-barplot2(meanapAprilactivity, col=columncolor,
xlab="Species", ylab="Soil acid phosphatase activity (nmol/h/g)",
ylim=c(0,1000), plot.ci=T, ci.l=apAprilminusordered,
ci.u=apAprilplusordered, cex.lab=1.5)#FinalGraphs>aPApril_Genus.pdf
>text(xvals,par("usr")[3]-1, srt=45, adj=0.5,labels=speciesnames,
xpd=T)
I have a few problems/questions:
1) The middle of the species names are placed at the bottom of the
bar, such that half of the label is in the figure.
Without any data that's a bit hard to reproduce. Use
dput(meanapAprilactivity )
And _what_ were your goals, anyway?
2) There is too much of a space between the genus and species name
(e.g. between Dialium and guianensis for my first species)
Ditto.
3) Do I use cex.axis to change the font size of the labels and
cex.lab to change the font size of xlab and ylab?
If you are referring to the text() call then cex will change the font
size of the labels.
I don't understand par() well enough to know what to change. I
figured changing the numbers after "usr" might help but I don't
understand what these numbers refer to and guess and check hasn't
gotten me anywhere.
The third value of par("usr") is the min y value (in the natural
units of the y variable) for the plot area, so if you were trying to
place the text near the bottom of the plotted region, then subtracting
1 from it to get your y-text argument _might_ work, but if the range
of y values is large you may overlap the lower border. Please describe
your goals, rather than relying on code that doesn't give the desired
result.
mp <- barplot2(VADeaths) # default
dimnames(VADeaths)[[2]]
# [1] "Rural Male" "Rural Female" "Urban Male" "Urban Female"
speciesnames <-c("Rural\nMale" , "Rural\nFemale","Urban\nMale" ,
"Urban\nFemale")
# increasing the value subtracted from y1 lowers the position of the
labels
xvals<-barplot2(VADeaths); text(xvals,par("usr")[3]-8, srt=45,
adj=0.5,labels=speciesnames, xpd=T)
Thanks,
Adrienne Keller
Graduate Student, College of Forestry
University of Montana
adrienne.kel...@umontana.edu
(Phone) 651-485-5822
______________________________________________
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.
David Winsemius, MD
West Hartford, CT
______________________________________________
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.