Cargamos e instalamos las librerias correspondientes

library(tables)
## Loading required package: Hmisc
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, round.POSIXt, trunc.POSIXt, units
library(knitr)
## Warning: package 'knitr' was built under R version 3.3.3

Leemos el fichero en cuestión y lo asigno a df.

df<- read.table("paMunMur0015DF.csv",sep=";",header=TRUE)                                                         

Con las funciones pertinentes, comprobamos la estructura y lo que representan las variables

head(df)
##   codMun      Mun year pobTotal pobHom pobMuj
## 1      1 Abanilla 2000     6106   3050   3056
## 2      1 Abanilla 2001     6033   3030   3003
## 3      1 Abanilla 2002     6040   3045   2995
## 4      1 Abanilla 2003     6239   3151   3088
## 5      1 Abanilla 2004     6145   3084   3061
## 6      1 Abanilla 2005     6265   3171   3094
str(df)
## 'data.frame':    720 obs. of  6 variables:
##  $ codMun  : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ Mun     : Factor w/ 45 levels "Águilas","Abanilla",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ year    : int  2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 ...
##  $ pobTotal: int  6106 6033 6040 6239 6145 6265 6333 6568 6642 6589 ...
##  $ pobHom  : int  3050 3030 3045 3151 3084 3171 3212 3350 3390 3315 ...
##  $ pobMuj  : int  3056 3003 2995 3088 3061 3094 3121 3218 3252 3274 ...

Seleccionamos los datos correspondientes al año 2000 y los guardamos en el objeto que nos indican

a2000 <- df [df$year=="2000", ]

Calculamos la población de Murcia para ese año

table(a2000$pobTotal,a2000$year)
##         
##          2000
##   593       1
##   959       1
##   997       1
##   1369      1
##   1568      1
##   1582      1
##   2035      1
##   3409      1
##   3908      1
##   5562      1
##   5749      1
##   6106      1
##   6814      1
##   7052      1
##   7305      1
##   7513      1
##   8116      1
##   8460      1
##   8888      1
##   10140     1
##   10753     1
##   10859     1
##   10972     1
##   12241     1
##   13738     1
##   14171     1
##   14516     1
##   14606     1
##   15583     1
##   15856     1
##   16003     1
##   18847     1
##   18925     1
##   20854     1
##   22250     1
##   22359     1
##   22719     1
##   27559     1
##   29319     1
##   32126     1
##   33453     1
##   44389     1
##   72000     1
##   179939    1
##   357166    1
# salvamos el "problema" del numero 1 con la función "aggregate" y "list"
aggregate( a2000$pobTotal, list( anho = a2000$year ), 
           sum, simplify = T )
##   anho       x
## 1 2000 1149328

Calculamos la población total de mujeres para cada año mediante una única expresión

tapply( df$pobMuj, df$year, sum )
##   2000   2001   2002   2003   2004   2005   2006   2007   2008   2009 
## 579203 594621 610757 629435 642637 658743 673279 685791 703110 714911 
##   2010   2011   2012   2013   2014   2015 
## 723352 728488 731722 732207 730929 731854

Calculamos la media del municipio que he elegido (guardado en “muni”) para el total, hombres y mujeres

muni <- df [df$Mun == "Archena",]
tapply( muni$pobTotal,muni$Mun=="Archena", mean )
##     TRUE 
## 17116.81
tapply( muni$pobMuj,muni$Mun=="Archena", mean )
##   TRUE 
## 8319.5
tapply( muni$pobHom,muni$Mun=="Archena", mean )
##     TRUE 
## 8797.312

Ahora hacemos todo lo referente a la funcion “tabular” para la poblacion masculina en el año 2015. Además nombramos propiamente a la columna que lo necesita.

a2015 <- df [df$year=="2015", ]
tt<-tabular(  ~ pobHom*( (media=mean) + sd + median + max + min  ), data = a2015 )
html( tt, 
      options = htmloptions( HTMLcaption = "Hombres en 2015" ),
      pad = TRUE)
Hombres en 2015
  pobHom
media sd median max min
16343 34857 7954 215177 270

Realizamos el gráfico como el del enunciado, introduciéndo en código pertinente

plot(muni$year,muni$pobTotal,type = "l",
     xlab = "Año", 
      ylab= "Número de habitantes", 
      main = "Archena",
     ylim = c( 0, max( muni$pobTotal )),
     lwd=3
     )
lines(muni$year,muni$pobHom,lwd=1,col="blue")
lines(muni$year,muni$pobMuj,lty=2,col="blue")
legend( "bottomright", 
        cex = 0.7,
        legend=c("Total","Mujeres","Hombres"),
        col = c("black", "blue", "blue"),
        title = "Poblaciones",
        lwd = 2:1,
        lty = 1:2)

Información de la sesión. Extra.

sessionInfo()
## R version 3.3.2 (2016-10-31)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
## 
## locale:
## [1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252   
## [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
## [5] LC_TIME=Spanish_Spain.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] knitr_1.15.1    tables_0.8      Hmisc_4.0-2     ggplot2_2.2.1  
## [5] Formula_1.2-1   survival_2.40-1 lattice_0.20-34
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.9         RColorBrewer_1.1-2  plyr_1.8.4         
##  [4] base64enc_0.1-3     tools_3.3.2         rpart_4.1-10       
##  [7] digest_0.6.12       evaluate_0.10       tibble_1.2         
## [10] gtable_0.2.0        htmlTable_1.9       checkmate_1.8.2    
## [13] Matrix_1.2-8        yaml_2.1.14         gridExtra_2.2.1    
## [16] stringr_1.2.0       cluster_2.0.5       htmlwidgets_0.8    
## [19] rprojroot_1.2       grid_3.3.2          nnet_7.3-12        
## [22] data.table_1.10.4   foreign_0.8-67      rmarkdown_1.3      
## [25] latticeExtra_0.6-28 magrittr_1.5        backports_1.0.5    
## [28] scales_0.4.1        htmltools_0.3.5     splines_3.3.2      
## [31] assertthat_0.1      colorspace_1.3-2    stringi_1.1.2      
## [34] acepack_1.4.1       lazyeval_0.2.0      munsell_0.4.3