Skip to content

Instantly share code, notes, and snippets.

@diegovalle diegovalle/largefam.R
Last active Aug 29, 2015

Embed
What would you like to do?
Población femenina de 40 a 44 años de edad con 4 o más hijos nacidos vivos y que habla una lengua indígena
require(ggplot2)
require(reshape)
require(stringr)
require(scales)
library(directlabels)
hom <- read.table(text="2010 2000 state
0.589481859 0.7044360966 Total
0.4050632911 0.4418604651 Aguascalientes
0.5746496039 0.6178509532 Baja California
0.534375 0.6626506024 Baja California Sur
0.5333139366 0.7060293658 Campeche
0.2647058824 0.4623655914 Coahuila
0.5702479339 0.5384615385 Colima
0.7112922835 0.751572327 Chiapas
0.6415348368 0.687756031 Chihuahua
0.3156605424 0.3905021659 Distrito Federal
0.7019002375 0.71019678 Durango
0.4948240166 0.5972696246 Guanajuato
0.7463112803 0.7846282898 Guerrero
0.5919600419 0.732226633 Hidalgo
0.5157534247 0.5814196242 Jalisco
0.5483870968 0.694105051 México
0.6119945479 0.7366684992 Michoacán
0.5200617284 0.6501736111 Morelos
0.7567365269 0.7991452991 Nayarit
0.3790720632 0.4744318182 Nuevo León
0.565286461 0.6998956306 Oaxaca
0.6172739798 0.7326110144 Puebla
0.6316316316 0.7102102102 Querétaro
0.4813463575 0.6953774526 Quintana Roo
0.6972944013 0.7758389262 San Luis Potosí
0.4993412385 0.663132137 Sinaloa
0.4657738095 0.6255299105 Sonora
0.5571360835 0.7361477573 Tabasco
0.3637305699 0.5470779221 Tamaulipas
0.5216080402 0.696969697 Tlaxcala
0.5986836214 0.7258441993 Veracruz
0.4924854918 0.6804862057 Yucatán
0.5608108108 0.6222222222 Zacatecas
", sep = "\t", row.names = NULL, header=TRUE,
colClasses = c("numeric", "numeric", "character"))
hom$diff <- hom$row.names - hom$X2010..2000
names(hom) <- c("2010", "2000", "state", "diff")
hom <- melt(hom, id = c("state", "diff"))
hom$variable <- as.integer(as.character(hom$variable))
hom$color <- ifelse(hom$diff < 0, "Salmon", "RoyalBlue")
p <- ggplot(hom, aes(variable, value, group = state, color = state)) +
geom_line(size = 1.2) +
scale_color_manual(values = c(rep("RoyalBlue ",7), "Salmon ", rep("RoyalBlue ", 21), "black",
rep("RoyalBlue ", 10))) +
scale_x_continuous(breaks = c(2000, 2010), limits = c(2000, 2011.5)) +
scale_y_continuous(limits =c(0, max(hom$value)), labels = percent) +
labs(title="Población femenina de 40 a 44 años de edad con 4 o más hijos nacidos vivos\n y que habla una lengua indígena(Censo 2000,2010)") +
xlab("año") +
ylab("porcentaje con 4 o más hijos")
direct.label(p, list("last.qp","reduce.cex.lr"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.