Skip to content

Instantly share code, notes, and snippets.

@patperu
Last active August 29, 2015 13:57
Show Gist options
  • Save patperu/9618545 to your computer and use it in GitHub Desktop.
Save patperu/9618545 to your computer and use it in GitHub Desktop.
Plot "G62 -- Grado di diffusione di Internet nelle famiglie"
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 1. in line 1.
# source: http://www.istat.it/it/files/2011/07/Societ%C3%A0_informazione.xls, pagina: 062
id;regione;1995;1996;1997;1998;1999;2000;2001;2002;2003;2004;2005;2006;2007;2008;2009;2010;2011;2012;2013
1;Piemonte;;;2,5;3,7;8,6;16,9;25,1;30,2;27,8;;32,8;33,5;37,4;40,0;46,2;50,8;53,7;53,5;58,2
2;Valle d'Aosta;;;2,0;3,6;7,5;14,8;26,4;26,4;32,1;;30,9;34,5;37,5;44,8;48,2;49,1;56,9;59,3;60,0
3;Lombardia;;;2,8;3,9;8,4;18,7;30,3;35,3;34,6;;39,4;42,0;45,7;48,6;50,6;57,7;59,9;60,4;64,7
4;Trentino-Alto Adige;;;1,8;3,7;8,8;17,5;29,9;36,9;32,7;;38,7;39,5;44,7;47,3;51,4;55,3;60,6;61,8;66,9
5;- Bolzano/Bozen;;;1,2;3,4;9,5;19,1;29,5;35,6;33,0;;41,3;39,9;43,9;50,3;54,0;55,0;60,6;63,3;69,6
6;- Trento;;;2,3;3,9;8,1;16,0;30,3;38,1;32,5;;36,3;39,1;45,4;44,6;49,1;55,7;60,6;60,7;63,9
7;Veneto;;;1,8;3,6;8,6;15,5;28,8;33,8;33,7;;38,0;38,3;43,2;44,4;50,1;55,1;57,3;57,9;66,6
8;Friuli-Venezia Giulia;;;2,1;4,6;7,8;16,2;24,8;34,0;29,8;;38,5;36,7;38,4;47,0;49,6;54,1;56,4;55,0;62,8
9;Liguria;;;2,5;3,4;7,7;13,3;24,3;26,9;30,4;;28,6;31,7;33,2;34,6;42,3;47,7;49,3;54,4;55,5
10;Emilia-Romagna;;;3,5;5,0;8,4;18,3;26,1;32,5;32,6;;35,9;38,1;39,6;46,8;50,8;53,4;55,7;59,0;64,6
11;Toscana;;;3,0;4,2;9,8;16,5;29,0;34,0;31,5;;37,1;39,7;41,5;41,3;48,8;53,6;58,6;55,7;62,3
12;Umbria;;;1,7;4,0;9,5;17,3;27,1;31,9;30,3;;37,7;37,6;40,9;42,9;48,6;52,4;52,0;54,6;63,5
13;Marche;;;2,1;2,6;8,9;16,1;25,5;33,5;33,9;;38,5;38,7;40,3;42,8;53,0;53,5;57,9;58,8;64,6
14;Lazio;;;3,9;4,7;11,2;19,4;28,3;32,9;33,0;;39,9;40,0;42,8;49,4;51,5;58,1;58,6;60,3;63,8
15;Abruzzo;;;2,4;1,5;5,7;15,5;27,6;27,7;32,8;;37,8;33,5;39,9;40,3;48,1;54,1;53,3;51,5;60,9
16;Molise;;;1,7;1,6;3,3;11,7;19,8;25,8;27,6;;29,4;34,4;37,6;41,3;45,5;44,1;48,8;48,0;51,2
17;Campania;;;1,4;2,5;4,9;12,9;23,3;22,7;29,1;;29,4;29,0;33,9;37,2;45,3;48,3;51,8;50,9;55,1
18;Puglia;;;1,6;2,5;5,1;9,4;19,5;22,9;24,4;;27,2;28,7;29,3;31,2;38,1;44,1;44,2;49,3;55,2
19;Basilicata;;;1,0;2,4;2,9;11,4;20,5;32,5;32,9;;35,3;36,3;34,3;38,5;39,9;44,2;45,0;44,1;55,0
20;Calabria;;;1,6;2,1;3,6;7,2;18,9;22,2;24,1;;28,8;27,2;31,7;33,5;38,6;46,8;46,3;47,1;51,6
21;Sicilia;;;0,9;2,1;4,7;9,8;15,6;21,3;21,2;;23,4;26,6;28,6;31,6;39,8;44,2;46,6;48,4;52,0
22;Sardegna;;;1,2;2,7;7,6;14,7;25,8;32,0;29,9;;36,3;36,7;41,6;44,2;49,5;56,5;55,7;57,5;62,4
23;Italia;;;2,3;3,5;7,6;15,4;25,5;30,1;30,3;;34,5;35,6;38,8;42,0;47,3;52,4;54,6;55,5;60,7
# see http://bit.ly/Nt5jpg
# http://www.datamediahub.it/2014/03/18/societa-dellinformazione-il-ritmo-di-crescita-delle-regioni-in-10-anni-mappa-interattiva/
library(ggplot2)
library(reshape2)
g62 <- read.csv2("g62.csv", skip = 1)
x <- g62[!colnames(g62) %in% paste0("X", 1995:2002)]
rownames(x) <- x$regione
ff <- function(df, id) {
m <- as.matrix(df)
data.frame(sweep(m, 2, m[id,], FUN ="/") * 100)
}
x1_rel <- ff(x[, -c(1:2)], "Italia")
x1_rel$d1303 <- x1_rel[, "X2013"] - x1_rel[, "X2003"]
p1 <- ggplot(x1_rel, aes(X2003, X2013)) + geom_point(aes(size = d1303), col = "blue", shape = 1)
p1 <- p1 + geom_hline(yintercept=100)
p1 <- p1 + geom_vline(xintercept=100)
p1 <- p1 + geom_abline(intercept=0, slope=1)
p1 <- p1 + geom_text(aes(label=rownames(x1_rel)), hjust = 0.5, vjust =0.8, angle=20, size = 3.5)
p1 <- p1 + labs(title = "G62 - Grado di diffusione di Internet nelle famiglie (Italia = 100)")
p1 <- p1 + xlab("Anno 2003") + ylab("Anno 2013")
p1 <- p1 + theme(aspect.ratio=1.0) + theme_bw()
x1_rel$regione <- rownames(x1_rel)
x1_rel_m <- x1_rel[!x1_rel$regione %in% c("Italia", "- Bolzano/Bozen", "- Trento"), ]
x1_rel_m <- melt(x1_rel, id.var="regione", variable.name = "anno")
x1_rel_m$anno <- gsub("X", "", x1_rel_m$anno)
x1_rel_m
p2 <- ggplot(subset(x1_rel_m, subset=anno != "d1303"),
aes(anno, value)) + geom_boxplot() + theme_bw()
p2 <- p2 + geom_hline(yintercept=100)
p2 <- p2 + xlab("Anno") + ylab("Percent (Italia = 100)")
p2 <- p2 + labs(title = "G62 - Grado di diffusione di Internet nelle famiglie (Italia = 100)")
p3 <- ggplot(subset(melt(x, id.vars= "regione"),
subset=!variable %in% c("id", "d1303")),
aes(variable, value)) + geom_boxplot() + theme_bw()
p3 <- p3 + labs(title = "G62 - Grado di diffusione di Internet nelle famiglie")
ggsave(p1, file= "g62a.pdf")
ggsave(p2, file= "g62b.pdf")
ggsave(p3, file= "g62c.pdf")
#
# FINI
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment