Add VT2-examples: all 6 chapters of 'Visualize This' (110 files) — data scraping, ETL, trends, categorical, multivariate, spatial, distribution analysis

This commit is contained in:
neo committed 2026-06-24 14:49:15 +05:00
1 parent 088771a9cf
commit b42b866a8c
110 files changed
+400895

No files matched your search

@@ -0,0 +1,77 @@
#
# Multi-line chart
#
# Load data
marstat <- read.csv("data/mar_w_age_all.tsv", sep="\t")
head(marstat)
unique(marstat$MARST)
# Subset married
married <- marstat[marstat$MARST == 1,]
# Line chart for 2021
married2021 <- married[married$YEAR == 2021,]
par(las=1)
plot(married2021$AGE, married2021$prop*100,
ylim=c(0, 100),
type="n",
bty="n", xaxt="n", yaxt="n",
xlab="", ylab="",
main="Proportion of people married, by age")
axis(1, tick=FALSE)
axis(2,
at=seq(0, 100, by=20),
labels=paste0(seq(0, 100, by=20), "%"),
tick=FALSE)
grid()
lines(married2021$AGE, married2021$prop*100,
lwd=2,
col="#b31dc2")
# All available years
plot(married2021$AGE, married2021$prop*100,
ylim=c(0, 100),
type="n",
bty="n", xaxt="n", yaxt="n",
xlab="", ylab="",
main="Proportion of people married, by age")
axis(1, tick=FALSE)
axis(2,
at=seq(0, 100, by=20),
labels=paste0(seq(0, 100, by=20), "%"),
tick=FALSE)
grid()
abline(h=0, lwd=2)
years <- unique(married$YEAR)
# Multiple lines with a for-loop
for (yr in years) {
curr <- married[married$YEAR == yr,]
lines(curr$AGE, curr$prop*100,
col="#b31dc2")
}
# Change line width for each year
for (yr in years) {
curr <- married[married$YEAR == yr,]
if (yr == 1900) {
lines(curr$AGE, curr$prop*100,
lwd=3,
col="green")
} else {
lines(curr$AGE, curr$prop*100,
lwd=min(c(3, 15*1/(2021-yr+.5))),
col="#b31dc2")
}
}