Escritura

setwd("/cloud/project")

Datos <- read.csv("DataSet_.csv", sep = ";", fileEncoding = "latin1")

install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(ggplot2)

Tabla Base

Pais <- Datos$country
TDF_pais <- table(Pais)

tabla_pais <- as.data.frame(TDF_pais)
hi <- tabla_pais$Freq/sum(tabla_pais$Freq)
hi_porc <- hi*100

tabla_PAIS <- data.frame(tabla_pais, hi_porc)

colnames(tabla_PAIS)[1] <- "Pais"

Agrupación

tabla_resumen <- tabla_PAIS %>%
  mutate(grupo = case_when(
    grepl("Argentina", Pais, ignore.case = TRUE) ~ "Argentina",
    grepl("Bolivia", Pais, ignore.case = TRUE) ~ "Bolivia",
    grepl("Brazil", Pais, ignore.case = TRUE) ~ "Brazil",
    grepl("Chile", Pais, ignore.case = TRUE) ~ "Chile",
    grepl("Colombia", Pais, ignore.case = TRUE) ~ "Colombia",
    grepl("Ecuador", Pais, ignore.case = TRUE) ~ "Ecuador",
    grepl("Guyana", Pais, ignore.case = TRUE) ~ "Guyana",
    grepl("Paraguay", Pais, ignore.case = TRUE) ~ "Paraguay",
    grepl("Peru", Pais, ignore.case = TRUE) ~ "Peru",
    grepl("Suriname", Pais, ignore.case = TRUE) ~ "Suriname",
    grepl("Uruguay", Pais, ignore.case = TRUE) ~ "Uruguay",
    grepl("Venezuela", Pais, ignore.case = TRUE) ~ "Venezuela",
    TRUE ~ "Otros"
  )) %>%
  group_by(grupo) %>%
  summarise(
    Frecuencia = sum(Freq),
    Porcentaje = sum(hi_porc)
  ) %>%
  arrange(desc(Frecuencia))

colnames(tabla_resumen) <- c("Pais","ni","hi (%)")
tabla_resumen
## # A tibble: 13 × 3
##    Pais         ni `hi (%)`
##    <chr>     <int>    <dbl>
##  1 Brazil     5745  80.4   
##  2 Colombia    703   9.84  
##  3 Chile       422   5.91  
##  4 Argentina    96   1.34  
##  5 Peru         75   1.05  
##  6 Ecuador      49   0.686 
##  7 Uruguay      23   0.322 
##  8 Bolivia      13   0.182 
##  9 Guyana        8   0.112 
## 10 Paraguay      3   0.0420
## 11 Suriname      3   0.0420
## 12 Otros         1   0.0140
## 13 Venezuela     1   0.0140

Totales

totales <- c(
  Pais = "TOTAL",
  ni = sum(tabla_resumen$ni),
  hi = sum(tabla_resumen$`hi (%)`)
)

tabla_Pais_Final <- rbind(tabla_resumen, totales)
tabla_Pais_Final
## # A tibble: 14 × 3
##    Pais      ni    `hi (%)`          
##    <chr>     <chr> <chr>             
##  1 Brazil    5745  80.439652758331   
##  2 Colombia  703   9.84318118174181  
##  3 Chile     422   5.90870904508541  
##  4 Argentina 96    1.34416129935592  
##  5 Peru      75    1.05012601512181  
##  6 Ecuador   49    0.686082329879586 
##  7 Uruguay   23    0.322038644637356 
##  8 Bolivia   13    0.182021842621115 
##  9 Guyana    8     0.112013441612994 
## 10 Paraguay  3     0.0420050406048726
## 11 Suriname  3     0.0420050406048726
## 12 Otros     1     0.0140016802016242
## 13 Venezuela 1     0.0140016802016242
## 14 TOTAL     7142  100

GRÁFICOS

Gráfico 1 – Frecuencia local

par(mar = c(9, 4, 4, 2))
barplot(tabla_resumen$ni,main="Gráfica N°1: Distribución de proyectos solares por País",
        ylab = "Cantidad",
        col = "skyblue",
        names.arg=tabla_resumen$Pais,
        cex.names = 0.8, las = 2)
mtext("País", side = 1, line = 8)

Gráfico 2 – Frecuencia global

barplot(tabla_resumen$ni,main="Gráfica N°2: Distribución de proyectos por País (Global)",
        ylab = "Cantidad",
        col = "skyblue",
        ylim = c(0,8000),
        names.arg=tabla_resumen$Pais,
        cex.names = 0.8, las = 2)
mtext("País", side = 1, line = 8)

Gráfico 3 – Porcentaje local

barplot(tabla_resumen$`hi (%)`,main="Gráfica N°3: Distribución porcentual por País",
        ylab = "Porcentaje %",
        col = "skyblue",
        names.arg=tabla_resumen$Pais,
        cex.names = 0.8, las = 2)
mtext("País", side = 1, line = 8)

Gráfico 4 – Porcentaje global

barplot(tabla_resumen$`hi (%)`,main="Gráfica N°4: Distribución porcentual global",
        ylab = "Porcentaje %",
        col = "skyblue",
        ylim = c(0,100),
        names.arg=tabla_resumen$Pais,
        cex.names = 0.8, las = 2)
mtext("País", side = 1, line = 8)

Gráfico 5 – Diagrama Circular

pie(tabla_resumen$`hi (%)`,
    main = "Gráfica N°5: Distribución porcentual de proyectos por País",
    radius = 0.9,
    labels = paste0(round(tabla_resumen$`hi (%)`,2),"%"),
    col = colores <- c(rev(heat.colors(length(tabla_resumen$Pais)))),
    cex = 0.6)

legend(x = 1.4, y = 0.8,
       legend = tabla_resumen$Pais,
       fill = colores,
       cex = 0.6,
       title = "País")

par(xpd = TRUE)

Tabla de Conlusiones

install.packages("knitr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(knitr)

tabla_indicadores <- data.frame(
  "Variable" = "País del proyecto",
  "Rango" = "Países de Sudamérica",
  "X" = "-",
  "Me" = "-",
  "Mo" = "Brazil",
  "V" = "-",
  "Sd" = "-",
  "Cv" = "-",
  "As" = "-",
  "K" = "-",
  "Valores Atipicos" = "-"
)

kable(tabla_indicadores, align = 'c', caption = "Conclusiones de la variable País")
Conclusiones de la variable País
Variable Rango X Me Mo V Sd Cv As K Valores.Atipicos
País del proyecto Países de Sudamérica - - Brazil - - - - - -