最近閱讀一篇文獻《Regional and individual variations in the function of the human eccrine sweat gland》,想看看里面幾個變量之間的關系是怎么樣,因此把文獻里面的數據提取出來,
在R里面輸入數據:
sample<-seq(1,14,by=1) forehead<-c(249,189,128,111,184,233,313,120,151,196,135,157,145,218) forearm<-c(176,28,136,87,145,109,151,63,101,95,121,98,97,102) back<-c(95,51,55,51,58,77,121,37,39,49,66,58,49,85) sweatgland<-data.frame(sample,forehead,forearm,back);sweatgland
數據如下圖所示:
一共有14個樣本,其中forehead,forearm,back為對應位置的數量
先畫出每個樣本的forehead位置的sweat gland 數量
plot(forehead~sample,pch=15,col="DarkTurquoise",ylim=c(0,400),ylab="Number of active sweat glands per cm2",main="Number of active sweat glands per cm2 in forehead, forearm and back")#pch表示散點用什么形狀表示,col表示顏色,ylim表示Y軸范圍,ylab表示Y軸標題,main表示圖片標題
接着畫出每個樣本forearm位置的sweat gland 數量
注意,這里不用plot函數畫forearm和sample之間的關系,因為會把上面forehead和sample的圖覆蓋住,為了實現多個因變量和一個自變量在同一個圖片里,我們要用points或者lines函數畫其他因變量和自變量的值
points(sample,forearm,pch=16,col="DeepPink",cex=1)#cex表示散點的大小
畫出back位置的sweat gland 數量
points(sample,back,pch=17,col="RosyBrown",cex=1)
把14個樣本在forehead,forearm和back不同位置的sweat gland 數量用線連起來
lines(forehead,col="DarkTurquoise",lty=1)#lty=1表示用實線連起來 lines(forearm,col="DeepPink",lty=2)#lty=2表示用虛線連起來 lines(back,col="RosyBrown",lty=3)#lty=3表示用點線連起來
legend函數,圖例說明:
legend(12,400,c("forehead","forearm","back"),col=c("DarkTurquoise","DeepPink","RosyBrown"),text.col=c("DarkTurquoise","DeepPink","RosyBrown"),pch=c(15,16,17),lty=c(1,2,3))#12表示x軸坐標為12,400表示y軸坐標為400,意思為圖例的左邊和上邊界限,text.col表示圖例文本顏色
最后,畫出來的圖片效果如下: