######################################################### #Nicol, A. A. M., & Pexman, P. M. (2003). #Plots. In Displaying your findings: A practical guide for creating figures, posters, and presentations (pp.73--82). #Washington, DC: American PsychologicalAssociation ######################################################### setwd("C:/data/Figure") #適当に作業フォルダを変更 ##データの作成 dat1 <- matrix(c( 54,68,53, 27,29,57, 35,50,81, 20,37,90, 23,39,81, 40,34,44, 49,59,59, 43,52,74, 69,94,58, 39,82,87, 30,71,89, 20,46,67, 55,64,56, 22,22,64, 31,48,51, 45,48,44, 73,76,56, 53,66,42, 46,42,51, 28,54,78, 77,79,35, 33,32,66, 67,86,66, 37,68,73, 27,40,68, 32,33,54, 54,64,43, 18,40,80, 42,56,70, 52,72,69, 37,70,76, 68,56,25, 55,57,65, 71,97,62, 77,86,35, 49,78,79, 41,60,69, 59,76,55, 18,26,54, 67,72,44, 70,71,38, 72,64,21, 66,76,58, 31,50,68, 42,55,67, 35,50,68, 75,71,32, 35,49,58, 49,56,53, 54,68,56, 53,64,60, 31,43,61, 11,21,66, 49,58,42, 52,55,46, 61,87,75, 67,94,75, 18,47,79, 22,46,81, 60,79,46, 34,82,91, 31,5,47, 32,52,70, 46,60,65, 49,59,57, 41,54,62, 58,67,56, 75,84,41, 68,55,18, 46,77,74 ),ncol=3,byrow=T) dat1 <- data.frame(dat1) names(dat1) <- c("Age","Voc","Read") #------------------------------# # Figure 4.1 #------------------------------# ##(a) 図を描画 windows(height=5,width=7) plot(Voc~Age,data=dat1, xlim=c(0,90),ylim=c(0,100), xlab="Age(Years)", ylab="Vocabulary Score", xaxt="n",yaxt="n") axis(side=1,at=seq(0,90,by=10)) axis(side=2,at=seq(0,100,by=10), las=1) ##(b) 図を出力 savePlot(filename="Fig4.1",type="wmf") graphics.off() #------------------------------# # Figure 4.2 #------------------------------# ##(a) 図を描画 windows(height=5,width=7) plot(Voc~Age,data=dat1, xlim=c(0,90),ylim=c(0,100), xlab="Age(Years)", ylab="Vocabulary Score", xaxt="n",yaxt="n") text(60,20, expression(italic(R^2)==".55"), pos=4) text(60,12, expression(italic(y)== 21.83 + 0.81*italic(x)),pos=4) axis(side=1,at=seq(0,90,by=10)) axis(side=2,at=seq(0,100,by=10), las=1) reg1 <- lm(Voc~Age,data=dat1) coef1 <- coef(reg1) abline(coef1) ##(b) 図を出力 savePlot(filename="Fig4.2",type="wmf") graphics.off() #------------------------------# # Figure 4.3 #------------------------------# ##(a) 図を描画 windows(height=5,width=7) plot(Voc~Age,data=dat1, xlim=c(0,90),ylim=c(0,100), xlab="Age(Years)", ylab="Vocabulary Score", xaxt="n",yaxt="n", bty="l") axis(side=1,at=seq(0,90,by=10)) axis(side=2,at=seq(0,100,by=10), las=1) ##(b) 図を出力 savePlot(filename="Fig4.3",type="wmf") graphics.off() #------------------------------# # Figure 4.4 #------------------------------# windows(height=5,width=7) reg1 <- lm(Voc~Age, data=dat1) reg2 <- lm(Read~Age, data=dat1) plot(Voc~Age,data=dat1, xlim=c(0,90),ylim=c(0,100), xlab="Age(Years)", ylab="Vocabulary Score", xaxt="n",yaxt="n", bty="l", pch=16) lines(Read~Age, data=dat1, type="p", pch=22) axis(side=1,at=seq(0,90,by=10)) axis(side=2,at=seq(0,100,by=10), las=1) abline(coef(reg1)) abline(coef(reg2)) par(xpd=T) text(75,30, expression(italic(R^2)==".55"), pos=4) text(75,22, expression(italic(y)== 21.83 + 0.81*italic(x)),pos=4) text(75,10, expression(italic(R^2)==".36"), pos=4) text(75,2, expression(italic(y)== 85.99 -0.57*italic(x)),pos=4) legend(0,15, legend=c("Vocabulary Score","Reading Comprehension Score"), pch=c(16,22)) ##(b) 図を出力 savePlot(filename="Fig4.4",type="wmf") graphics.off()