-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptII_quan_EDA_case_Suisse-fertility_helpfuncs.r
79 lines (60 loc) · 2.15 KB
/
ptII_quan_EDA_case_Suisse-fertility_helpfuncs.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
### (C) 2005-2023 by Leo Guertler
### R-code supplement
### to the book
###
### "Subjektive Ansichten und objektive Betrachtungen"
###
### written by Gürtler & Huber (2023)
###
### All R-code is published under the GPL v3 license:
###
### https://www.gnu.org/licenses/gpl-3.0.en.html
###
### except for 'borrowed' code - see links and references.
### For this R-code the original license of the respective
### authors is valid.
###
### R-code published on
###
### https://osdn.net/projects/mixedmethod-rcode
### https://github.com/abcnorio/mixedmethod-rcode
# file:
# ptII_quan_EDA_case_Suisse-fertility_helpfuncs.r
# location:
# chap. 5 [5.5.2]
# Fruchtbarkeit und Fertilität
# HELPFER FUNCTIONS
###### function to plot two variables along with a continuous index
scaplot.cont <- function(x,y, TITLE="", SUB="", xtext="", ytext="", legendTITLE="", fac=1.1)
{
xlim <- range(x)
ylim <- range(y)
layout(matrix(1:2,ncol=2), width = c(2,1),height = c(1,1))
par(mar=c(5,5,4,2))
par(oma=c(2,1,1,1))
par("cex.axis"=0.8)
plot(x,y, main="", xlab="", ylab="", cex.lab=0.8, cex.axis=0.8, bty="n", axes=F, col="white")
axis(side = 1, pretty(xlim), tck =- .02, labels=NA, line=.6)
axis(side = 2, pretty(ylim), tck = -.02, labels=NA, line=.6)
axis(side = 1, lwd = 0, line = .4)
axis(side = 2, lwd = 0, line = .4, las = 1)
mtext(TITLE, 3, line=2, cex=1.5)
mtext(SUB, 3, line=.252, cex=1.1)
grid(col="grey80", lwd=1.2, lty=1)
mtext(xtext, 1, line=4, cex=1)
mtext(ytext, 2, line=4, cex=1)
# color ramp based on x
require(hexbin)
plotcolo <- BTC(length(x))
points(x, y, col=plotcolo, pch=21, bg=plotcolo, bty="n", cex=fac)
legend_image <- as.raster(matrix(plotcolo, ncol=1))
plot(c(0,2), c(0,1), type ="n", axes=F, xlab="", ylab="", main=legendTITLE)
legtext <- seq(floor(min(y)), ceiling(max(y)), l=5)
text(x=1.5, y=seq(0, 1, l=5), labels=legtext)
rasterImage(legend_image, 0, 0, 1,1)
}
# call:
# scaplot.cont(x=swiss$Catholic, y=swiss$Fertility,
# TITLE="Swiss data on Fertility from 1888", SUB="Fertility versus Catholic",
# legendTITLE="Catholic Index", xtext="Catholic", ytext="Fertility")
########################## END OF FUNCTION