[R] Tables with Graphical Representations

Greg Snow Greg.Snow at intermountainmail.org
Fri Sep 1 18:25:55 CEST 2006


The LaTeX or other solutions suggested are probably best, but here is a
way to do it using only R base graphics (the below code is to get you
started, some graphical parameters need to be set to get the spacing to
look better):

 tmp <- structure(list(Cancer = structure(as.integer(c(19, 23, 22, 13, 
2, 7, 5, 24, 3, 9, 20, 8, 4, 15, 16, 17, 10, 1, 14, 21, 12, 6, 
11, 18)), .Label = c("Brain, nervous system", "Breast", "Cervis, uteri",

"Colon", "Corpus uteri, uterus", "Esophagus", "Hodgkin's Disease", 
"Kidney, renal pelvis", "Larynx", "Leukemia", "Liver, bile duct", 
"Lung and bronchus", "Melanomas", "Multiple myeloma", "Non-Hodgkin's", 
"Oral cavity, pharynx", "Ovary", "Pancreas", "Prostate", "Rectum", 
"Stomach", "Testis", "Thyroid", "Urinary, bladder"), class = "factor"), 
    p5 = c(98.8, 96, 94.7, 89, 86.4, 85.1, 84.3, 82.1, 70.5, 
    68.8, 62.6, 61.8, 61.7, 57.8, 56.7, 55, 42.5, 32, 29.5, 23.8, 
    15, 14.2, 7.5, 4), s5 = c(0.4, 0.8, 1.1, 0.8, 0.4, 1.7, 1, 
    1, 1.6, 2.1, 1.2, 1.3, 0.8, 1, 1.3, 1.3, 1.2, 1.4, 1.6, 1.3, 
    0.4, 1.4, 1.1, 0.5), p10 = c(95.2, 95.8, 94, 86.7, 78.3, 
    79.8, 83.2, 76.2, 64.1, 56.7, 55.2, 54.4, 55.4, 46.3, 44.2, 
    49.3, 32.4, 29.2, 12.7, 19.4, 10.6, 7.9, 5.8, 3), s10 = c(0.9, 
    1.2, 1.3, 1.1, 0.6, 2, 1.3, 1.4, 1.8, 2.5, 1.4, 1.6, 1, 1.2, 
    1.4, 1.6, 1.3, 1.5, 1.5, 1.4, 0.4, 1.3, 1.2, 1.5), p15 = c(87.1, 
    94, 91.1, 83.5, 71.3, 73.8, 80.8, 70.3, 62.8, 45.8, 51.8, 
    49.8, 53.9, 38.3, 37.5, 49.9, 29.7, 27.6, 7, 19, 8.1, 7.7, 
    6.3, 2.7), s15 = c(1.7, 1.6, 1.8, 1.5, 0.7, 2.4, 1.7, 1.9, 
    2.1, 2.8, 1.8, 2, 1.2, 1.4, 1.6, 1.9, 1.5, 1.6, 1.3, 1.7, 
    0.4, 1.6, 1.5, 0.6), p20 = c(81.3, 95.4, 88.2, 82.8, 65, 
    67.1, 79.2, 67.9, 60, 37.8, 49.2, 47.3, 52.3, 34.3, 33, 49.6, 
    26.2, 26.1, 4.8, 14.9, 6.5, 5.4, 7.6, 2.7), s20 = c(3, 2.1, 
    2.3, 1.9, 0.7, 2.8, 2, 2.4, 2.4, 3.1, 2.3, 2.6, 1.6, 1.7, 
    1.8, 2.4, 1.7, 1.9, 1.5, 1.9, 0.4, 2, 2, 0.8)), .Names = c("Cancer",

"p5", "s5", "p10", "s10", "p15", "s15", "p20", "s20"), row.names =
c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"
), class = "data.frame")

layout( matrix( c(1,1,2,3,4,5), nrow=1) )
barplot( rep(0, length(tmp$Cancer)), horiz=T, xaxt='n', space=.5,
	name=as.character(tmp$Cancer),las=1,cex.names=1)

ypos <- barplot( rbind(tmp$p5, 100-tmp$p5), horiz=T, xaxt='n', 
	space=.5, names=tmp$p5, cex.names=1, las=1)
title('5 year Survival',cex=.9)
axis(4, at=ypos, labels=tmp$s5, las=1, cex=.7,tick=F)

ypos <- barplot( rbind(tmp$p10, 100-tmp$p10), horiz=T, xaxt='n', 
	space=.5, names=tmp$p10, cex.names=1, las=1)
title('10 year Survival',cex=.9)
axis(4, at=ypos, labels=tmp$s10, las=1, cex=.7,tick=F)

ypos <- barplot( rbind(tmp$p15, 100-tmp$p15), horiz=T, xaxt='n', 
	space=.5, names=tmp$p15, cex.names=1, las=1)
title('15 year Survival',cex=.9)
axis(4, at=ypos, labels=tmp$s15, las=1, cex=.7,tick=F)

ypos <- barplot( rbind(tmp$p20, 100-tmp$p20), horiz=T, xaxt='n', 
	space=.5, names=tmp$p20, cex.names=1, las=1)
title('20 year Survival',cex=.9)
axis(4, at=ypos, labels=tmp$s20, las=1, cex=.7,tick=F)




-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Sam Ferguson
Sent: Thursday, August 31, 2006 5:50 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Tables with Graphical Representations

Hi useRs -

I was wondering if anyone out there can tell me where to find R-code to
do mixes of tables and graphics. I am thinking of something similar to
this:
http://yost.com/information-design/powerpoint-corrupts/
or like the excel routines people are demonstrating:
http://infosthetics.com/archives/2006/08/excel_in_cell_graphing.html

My aim is to provide small graphics to illustrate numbers directly
beside or behind their position in the table. Maybe there is a way to do
it with lattice?

Thanks for any help you may be able to provide.
Sam Ferguson

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list