forked from kiat/R-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module-4-Example-3.R
46 lines (31 loc) · 1.36 KB
/
Module-4-Example-3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# setwd("SET THE Working Director to THE PATH TO THIS DIRECTORY")
states <- read.csv("Datasets/states.csv")
attach(states)
data <- data.frame(poverty, metro_res, white, hs_grad, female_house)
# Data is about poverty in 50 states plus district of Colombia.
#
# The variables are percentage living in poverty in each state,
# percentage of residents living in a metropolitan area, percentage white,
# percentage of high school graduates, and percentage of female head of householders.
## put correlations on the upper panels,
## with size proportional to the correlations.
panel.cor <- function(x, y, digits=2, prefix="", 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]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor))
cex <- 0.8/strwidth(txt)
test <- cor.test(x,y)
# borrowed from printCoefmat
Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " "))
text(0.5, 0.5, txt, cex = cex * r)
text(.8, .8, Signif, cex=cex, col=2)
}
pairs(data, upper.panel = panel.cor)
# See read the five ways to visualize pairwise comparisions
# https://www.r-bloggers.com/five-ways-to-visualize-your-pairwise-comparisons/