[R] Can I make my colnames bold?

David Winsemius dwinsemius at comcast.net
Sat Dec 18 03:40:45 CET 2010


On Dec 17, 2010, at 7:30 PM, beloitstudent wrote:

>
> Hello forum!  As the subject indicates, I am trying to make a  
> barplot and
> would like my column names to be in bold.  Is this possible in R  
> without
> having to make my column names in mtext?  Any help would be much
> appreciated.  The code I am using is as follows.
>
> par(mar=c(3,8,2,2))
> par(adj=.5)
> par(font=2)
> par(oma=c(3,3,3,3))
> par(xpd=TRUE)
>
> Blot<-matrix(c(25.2995, 0.7625, 25.6135, 36.5770, 39.7085, 29.0730,  
> 38.1240,
> 10.5205,45.3135), ncol=3, byrow=TRUE)
> colnames(Blot)<-c("Pancreas", "Liver", "Muscle")
> rownames(Blot)<-c("0 hour fast", "5 hour fast", "10 hour fast")
> blot<-as.table(Blot)
>
> barplot(blot,beside=TRUE, col=c('darkorchid1','darkorchid3',  
> 'darkorchid4'),
> ylim=c(0,80), yaxp=c(0,80,8), font.lab=2,  las=1,  
> axes=FALSE,cex.lab=1.6)
>
> axis(2, at=c("0", "10",  "20", "30", "40", "50", "60", "70"), lwd=2,
> font=1.7, pos=-.025,cex.axis=2, las=2)
>
> mtext("Relative Intensity", side=2, line=6, adj=.525, cex=2, font=1)
>
> arrows(1.5, 25.2995, 1.5, 36.7875, code=2, angle=90, lwd=2, length=.1)
> arrows(2.5, 36.577, 2.5, 48.065, code=2, angle=90, lwd=2, length=.1)
> arrows(3.5, 38.124, 3.5, 49.612, code=2, angle=90, lwd=2, length=.1)
>
> arrows(5.5, 0.7625, 5.5,24.2575, code=2, angle=90, lwd=2, length=.1)
> arrows(6.5, 39.7085, 6.5,63.2035, code=2, angle=90, lwd=2, length=.1)
> arrows(7.5, 10.5205, 7.5,34.0155, code=2, angle=90, lwd=2, length=.1)
>
> arrows(9.5, 25.6135, 9.5,29.8331, code=2, angle=90, lwd=2, length=.1)
> arrows(10.5, 29.073, 10.5,33.2926, code=2, angle=90, lwd=2, length=.1)
> arrows(11.5, 45.3135, 11.5,49.5331, code=2, angle=90, lwd=2, length=. 
> 1)
>
>
> legend(7.5, 80, c("0 hour fast", "5 hour fast", "10 hour fast"),  
> bty="n",
> adj=0, fill=c('darkorchid1','darkorchid3','darkorchid4'),  
> text.col="black",
> cex=1.3)
>
> arrows(-.025, 0, 12, 0, code=0, angle=180, lwd=2)

Brute force solution:

par(mar=c(3,8,2,2))
par(adj=.5)
par(font=2)
par(oma=c(3,3,3,3))
par(xpd=TRUE)

Blot<-matrix(c(25.2995, 0.7625, 25.6135, 36.5770, 39.7085, 29.0730,  
38.1240,
10.5205,45.3135), ncol=3, byrow=TRUE)
colnames(Blot)<-c(")
rownames(Blot)<-c("0 hour fast", "5 hour fast", "10 hour fast")
blot<-as.table(Blot)

bpos <- barplot(blot,beside=TRUE, col=c('darkorchid1','darkorchid3',  
'darkorchid4'),
ylim=c(0,80), yaxp=c(0,80,8), font.lab=2,  las=1, xaxt="n",  
axes=FALSE,cex.lab=1.6)

axis(2, at=c("0", "10",  "20", "30", "40", "50", "60", "70"), lwd=2,
font=1.7, pos=-.025,cex.axis=2, las=2)
axis(1, at=bpos[c(2,5,8)], labels=expression(bold(Pancreas),  
bold(Liver), bold(Muscle) ) )

arrows(1.5, 25.2995, 1.5, 36.7875, code=2, angle=90, lwd=2, length=.1)
arrows(2.5, 36.577, 2.5, 48.065, code=2, angle=90, lwd=2, length=.1)
arrows(3.5, 38.124, 3.5, 49.612, code=2, angle=90, lwd=2, length=.1)

arrows(5.5, 0.7625, 5.5,24.2575, code=2, angle=90, lwd=2, length=.1)
arrows(6.5, 39.7085, 6.5,63.2035, code=2, angle=90, lwd=2, length=.1)
arrows(7.5, 10.5205, 7.5,34.0155, code=2, angle=90, lwd=2, length=.1)

arrows(9.5, 25.6135, 9.5,29.8331, code=2, angle=90, lwd=2, length=.1)
arrows(10.5, 29.073, 10.5,33.2926, code=2, angle=90, lwd=2, length=.1)
arrows(11.5, 45.3135, 11.5,49.5331, code=2, angle=90, lwd=2, length=.1)


legend(7.5, 80, c("0 hour fast", "5 hour fast", "10 hour fast"),  
bty="n",
adj=0, fill=c('darkorchid1','darkorchid3','darkorchid4'),  
text.col="black",
cex=1.3)

arrows(-.025, 0, 12, 0, code=0, angle=180, lwd=2)

>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Can-I-make-my-colnames-bold-tp3093323p3093323.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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



More information about the R-help mailing list