c("plotrix")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
set.seed(123)
sample(1:6, 100, replace=TRUE)
dice <- table(dice)) (dTab <-
dice
1 2 3 4 5 6
17 16 20 14 18 15
barplot(dTab, ylim=c(0, 30), xlab="Result", ylab="N", col="black",
main="Absolute frequency")
barplot(prop.table(dTab), ylim=c(0, 0.3), xlab="Result",
ylab="relative frequency", col="gray50",
main="Relative frequency")
# not shown
dice[1:50]
roll1 <- dice[51:100]
roll2 <- rbind(table(roll1), table(roll2))
rollAll <-rownames(rollAll) <- c("first", "second"); rollAll
1 2 3 4 5 6
first 8 9 8 7 7 11
second 9 7 12 7 11 4
barplot(rollAll, beside=FALSE, legend.text=TRUE, xlab="Result", ylab="N",
main="Absolute frequency in two samples")
barplot(rollAll, beside=TRUE, ylim=c(0, 15), col=c("red", "green"),
legend.text=TRUE, xlab="Result", ylab="N",
main="Absolute frequency in two samples")
100
N <- sample(18:45, N, replace=TRUE)
age <- c("beer", "red wine", "white wine")
drinks <- factor(sample(drinks, N, replace=TRUE))
pref <- round(range(age), -1) + c(-10, 10)
xRange <- c(18, 25, 35, 45)
lims <-spineplot(x=age, y=pref, xlab="Age class", ylab="drink", breaks=lims,
main="Preferred drink by age class")
cut(age, breaks=lims, labels=LETTERS[1:(length(lims)-1)])
ageCls <- factor(sample(letters[1:2], N, replace=TRUE))
group <- table(ageCls, pref, group)
cTab <-mosaicplot(cTab, cex.axis=1)
sample(1:6, 100, replace=TRUE)
dice <- table(dice)
dTab <-pie(dTab, col=c("blue", "red", "yellow", "pink", "green", "orange"),
main="Relative frequencies from rolling dice")
prop.table(dTab)
dTabFreq <- 0.5
textRad <- dTabFreq * 2 * pi
angles <- cumsum(angles)
csAngles <- csAngles - angles/2
csAngles <- textRad * cos(csAngles)
textX <- textRad * sin(csAngles)
textY <-text(x=textX, y=textY, labels=dTabFreq)
library(plotrix)
pie3D(dTab, theta=pi/4, explode=0.1, labels=names(dTab))
100
N <- rnorm(N, 175, 7)
X <- 0.5*X + rnorm(N, 0, 6)
Y <- cut(Y, breaks=c(-Inf, median(Y), Inf), labels=c("lo", "hi"))
Yfac <- data.frame(X, Yfac) myDf <-
cdplot(Yfac ~ X, data=myDf)
More plot types for categorical data are available in packages vcd
and vcdExtra
.
try(detach(package:plotrix))
R markdown - markdown - R code - all posts