수정 된 산점도 매트릭스 : 히스토그램을 추가하려면
panel.smooth<-function (x, y, col = "blue", bg = NA, pch = 18,
cex = 0.8, col.smooth = "red", span = 2/3, iter = 3, ...)
{
points(x, y, pch = pch, col = col, bg = bg, cex = cex)
ok <- is.finite(x) & is.finite(y)
if (any(ok))
lines(stats::lowess(x[ok], y[ok], f = span, iter = iter),
col = col.smooth, ...)
}
, panel.hist()
기능이 정의되어야한다
panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5))
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
}
최종 플롯 (pairs()
의 도움말 파일에서 가져온)
%% 히스토그램에 대한 수정 된 기능; panel.smooth
와
는 panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5))
par(cex.axis=2, family="Times New Roman", face="bold", size=12, cex.lab=1, cex.main=1, cex.sub=1)
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
}
%% 수정 회귀 함수; panel.cor
와
는 panel.smooth<-function (x, y, col = "black", bg = NA, pch = 16,
cex = 2, col.smooth = "red", span = 2/3, iter = 3, ...)
{
points(x, y, pch = pch, col = col, bg = bg, cex = cex)
ok <- is.finite(x) & is.finite(y)
if (any(ok))
lines(stats::lowess(x[ok], y[ok], f = span, iter = iter),
col = col.smooth, ...)
}
%% 수정 상관 함수;
panel.cor <- function(x, y, digits=2, cex.cor)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1]
test <- cor.test(x,y)
Signif <- ifelse(round(test$p.value,3)<0.001,"p < 0.001",paste("p = ",round(test$p.value,3)))
text(0.5, 0.25, paste("r = ",txt), cex = 2.5, family="Times New Roman", face="bold", size=12)
text(.5, .75, Signif, cex = 2.5, family="Times New Roman", face="bold", size=12)
}
는 산점도 행렬을 플롯 할 수 있으려면, 당신은 또한 "굴림"글꼴을 설치해야합니다. 이를 수행하려면 아래 단계를 따르십시오.
%% 모든 글꼴을 RStudio에 설치하십시오. 플롯의 품질을 향상시키는 것이 중요합니다!
install.packages("extrafont") # Install fonts
library(extrafont) # Install library
font_import() # Import all fonts
loadfonts(device="win") # Register fonts for Windows bitmap output
fonts() # Finish the process
%% 마지막으로, pairs
기능을 사용하여 그림을 그릴;
pairs(qq1, lower.panel=panel.smooth, upper.panel=panel.cor ,diag.panel=panel.hist, cex = 2, cex.labels = 2, cex.main = 2)
%% 최종 제품을 확인하십시오. enter image description here
많이 묻지 만 시도한 것을 표시하지 않습니다. 나는 당신이 격자 포장 안에 이것을하기 위하여 운을 더 가지고 있다고 생각한다. '? splom'을 참조하십시오. – agstudy
@agstudy 죄송합니다. 저는 R 언어를 처음 접했습니다. 어떻게해야할지 모르겠습니다. 나는 쌍을 시도했다. (USJudgeRatings [, c (2 : 3,6,1,7)], lower.panel = panel.smooth, upper.panel = panel.cor, pch = 18, col = "blue" 약간의 오류. –
페어링 된 데이터의 산점도에 맞는 라인이 표시됩니다. 피팅에 사용되는 방법은 무엇입니까? 위의 코드로 피팅이 정의 된 라인은 무엇입니까? 그리고 피팅 방법을 바꾸는 방법? –