R_Lattice_Graphics2

4505 days ago by takepwave

# Rのユーティリティ関数を読み込む attach(DATA+'RUtil.py') 
       
#r('install.packages("lattice")') r('library(lattice)') 
       
[1] "lattice"   "stats"     "graphics"  "grDevices" "utils"    
"datasets"  "methods"   "base"     
[1] "lattice"   "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base"     
r('VADeaths') 
       
      Rural Male Rural Female Urban Male Urban Female
50-54       11.7          8.7       15.4          8.4
55-59       18.1         11.7       24.3         13.6
60-64       26.9         20.3       37.0         19.3
65-69       41.0         30.9       54.6         35.1
70-74       66.0         54.3       71.1         50.0
      Rural Male Rural Female Urban Male Urban Female
50-54       11.7          8.7       15.4          8.4
55-59       18.1         11.7       24.3         13.6
60-64       26.9         20.3       37.0         19.3
65-69       41.0         30.9       54.6         35.1
70-74       66.0         54.3       71.1         50.0
r('class(VADeaths)') 
       
[1] "matrix"
[1] "matrix"
r('methods("dotplot")') 
       
[1] dotplot.array*   dotplot.default* dotplot.formula* dotplot.matrix* 
dotplot.numeric*
[6] dotplot.table*  

   Non-visible functions are asterisked
[1] dotplot.array*   dotplot.default* dotplot.formula* dotplot.matrix*  dotplot.numeric*
[6] dotplot.table*  

   Non-visible functions are asterisked
# 使い方はヘルプで確認できます。 #r('help(dotplot.matrix)') 
       

4.1 ドット・プロット

1940年バージニア州の死亡率を年齢別、住民グループ別にプロット。

graph = preGraph("fig4_1.pdf") r('tp1<-dotplot(VADeaths, groups = FALSE)') r('plot(tp1)') postGraph(graph) 
       
graph = preGraph("fig4_3.pdf") r('tp1<-dotplot(VADeaths, type = "o", auto.key = list(lines = TRUE, space = "right"), main = "Death Rates in Virginia - 1940", xlab = "Rate (per 1000)")') r('plot(tp1)') postGraph(graph) 
       

4.2 バー・プロット

 

graph = preGraph("fig4_4.pdf") r('tp1<-barchart(VADeaths, groups = FALSE, layout = c(1, 4), aspect = 0.7, reference = FALSE, main = "Death Rates in Virginia - 1940", xlab = "Rate (per 1000)")') r('plot(tp1)') postGraph(graph) 
       
r('data(postdoc, package = "latticeExtra")') graph = preGraph("fig4_5.pdf") r('tp1<-barchart(prop.table(postdoc, margin = 1), xlab = "Proportion", auto.key = list(adj = 1))') r('plot(tp1)') postGraph(graph) 
       
graph = preGraph("fig4_6.pdf") r('tp1<-dotplot(prop.table(postdoc, margin = 1), groups = FALSE, xlab = "Proportion", par.strip.text = list(abbreviate = TRUE, minlength = 10))') r('plot(tp1)') postGraph(graph) 
       

上記の図は、パネルのテキストが途中で切れてしまうので、短縮系で表示している。

graph = preGraph("fig4_6a.pdf") r('tp1<-dotplot(prop.table(postdoc, margin = 1), groups = FALSE, xlab = "Proportion")') r('plot(tp1)') postGraph(graph)