Graphics and statistics for cardiology: comparing categorical and continuous variables
Outline
Introduction
Graphs for display of single variable
Graphs comparing two variables
Graphs illustrating more than two variables
Introduction
- describe appropriate use of graphs.
- recommend particular types of graph.
- describe why they are good choices
- All the examples are drawn from NHANES 2003–2004 and 2005–2006 datasets and 「金錢誘因、動機與教師研究生產力」 -「金錢誘因、動機與教師研究生產力」來源為「學術調查研究資料庫」(Survey Research Data Archive),由國立臺灣大學教務處師資培育中心為探討金錢誘因與教師研究表現之間的關係,以我國9所大學493位專任教師為對象,蒐集人口變項、動機和長期研究生產力資料。
Graphs for display of a continuous variable
Dot chart (n=30)
Stacked dot chart (n=30)
library("beeswarm")
with(nhanessmall, beeswarm(BPXSAR, breaks=NA, vertical=FALSE, pch=1, method="center", xlab="Systolic BP (mmHg)"))Stacked dot chart(n=200)
library("beeswarm")
with(nhanesmedium, beeswarm(BPXSAR, breaks=NA, vertical=FALSE, pch=1, method="center", xlab="Systolic BP (mmHg)"))Violin plot(n=1000)
nhaneslarge <- read.csv("http://faculty.washington.edu/kenrice/heartgraphs/nhaneslarge.csv", na=".")
library("sm")
library("vioplot")
vioplot(nhaneslarge$BPXSAR, h=3, names="", horizontal=TRUE, col="grey90", drawRect=FALSE)
mtext(side=1, line=3, "Systolic BP (mmHg)")
points(x=mean(nhaneslarge$BPXSAR), y=1, pch=16, col="blue")
points(x=median(nhaneslarge$BPXSAR), y=1, pch=18, col="red")
legend("topright", pch=c(16,18), col=c("blue","red"), c("Sample mean","Sample median"), bty="n")大學專任教師每周平均研究時數
Graphs for display of categorical variables
Dot chart of proportion
Stacked bar chart
par(mar=c(4,2,4,0.3)+0.3, xpd=TRUE)
barplot(as.matrix(table(nhaneslarge$race_ethc)/1000), beside=FALSE, horiz=TRUE, xlim=c(0,1),
xlab="Proportion\n")
legend("top", inset=c(0, -0.5), fill=gray.colors(4), horiz=TRUE, bty="n", levels(nhaneslarge$race_ethc))