特定のデータセットの各数値変数の基本的なデータ統計を表示する小さな関数が必要です。これまでのところ、次のものがあります。
AnalyzeNumericData <- function(x,GroupVar=NA) {
VarList <- names(x)
NumVars <- length(VarList)
for (i in (1:NumVars)) {
if (is.numeric(x[,VarList[i]])) {
par(mfrow=c(2,2))
hist(x[,VarList[i]],main=paste("Histogram of ",VarList[i]),xlab=NA)
boxplot(x[,VarList[i]],main=paste("Boxplot of ",VarList[i]))
if (!is.na(GroupVar)) {
boxplot(x[,VarList[i]]~x[,GroupVar],main=paste("Boxplot of ",VarList[i]," by ", GroupVar))
}
# Add some text to bottom right
# I've tried plot(1)
# and then text(1,"MyText"), but this only alows me to put text on one place (in the middle of the plot)
}
}
}
AnalyzeNumericData(mtcars,"cyl")
この関数は、数値変数ごとに 3 つのグラフを作成します。右下の領域に 4 番目のグラフの代わりにテキストを追加したいと思います。text() は知っていますが、これを使用するには、最初に空のチャートのようなものを作成する必要があります。
どんなアイデアでも大歓迎です。