library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble 3.1.6 v purrr 0.3.4
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::between() masks data.table::between()
## x dplyr::filter() masks stats::filter()
## x dplyr::first() masks data.table::first()
## x dplyr::lag() masks stats::lag()
## x dplyr::last() masks data.table::last()
## x purrr::map() masks maps::map()
## x purrr::transpose() masks data.table::transpose()
cel %>%
filter(congress == 115) %>%
mutate( Mayoria = ifelse(majority == 1, "Majority", "Minority")) %>%
ggplot(aes(Mayoria, les)) +
geom_boxplot() +
ggtitle("LES in the 115th Congress") + # TÃtulo del plot
xlab("Majority or Minority") +
ylab ("Legislative Effectiveness")
####PuntoDos
library(stats)
# Creando Vectores.
Estudiante <- c("Diana","David","Carol")
Semestre <- c(1,1,1,2,2,2,
3,3,3,4,4,4,
5,5,5,6,6,6)
set.seed(1234)
Grado <- runif(18, min=80, max=100)
#Data.Frame
datos <- data.frame(Estudiante, Semestre, Grado)
#Gráfico
library(ggplot2)
ggplot(datos, aes(x=Semestre, y=Grado, group = Estudiante, colour =Estudiante )) +
geom_line() +
geom_point( size=2, shape=21, fill="white") +
theme_gray()+
facet_wrap(vars(Estudiante), nrow = 1)
####PuntoTres
cel %>%
filter(congress == 115) %>%
mutate (Genre = ifelse(female == 1,"Male","Female")) %>%
ggplot(aes(x= year, y=all_pass, fill = Genre ))+
geom_col()+
ggthemes::theme_fivethirtyeight()+
scale_y_continuous(labels = scales::percent)
####PuntoCuatro
library(sf)
## Warning: package 'sf' was built under R version 4.1.3
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
##
## Attaching package: 'sf'
## The following object is masked from 'package:transformr':
##
## st_normalize
library(rnaturalearth)
## Warning: package 'rnaturalearth' was built under R version 4.1.3
library(rnaturalearthdata)
## Warning: package 'rnaturalearthdata' was built under R version 4.1.3
library(rgeos)
## Warning: package 'rgeos' was built under R version 4.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.1.3
## rgeos version: 0.5-9, (SVN revision 684)
## GEOS runtime version: 3.9.1-CAPI-1.14.2
## Please note that rgeos will be retired by the end of 2023,
## plan transition to sf functions using GEOS at your earliest convenience.
## GEOS using OverlayNG
## Linking to sp version: 1.4-6
## Polygon checking: TRUE
library(ggplot2)
#Base de datos #1
mapa_mundo = map_data("world")
View(mapa_mundo)
ggplot(data = mapa_mundo, aes(x = long, y = lat, group=group))+
geom_polygon(color= "black", fill = "white")
suramerica<- mapa_mundo %>%
filter(region == c("Argentina","Colombia", "Ecuador", "Peru","Bolivia","Brazil","Chile","Ecuador","Guyana",
"Paraguay","Suriname","Uruguay","Venezuela"))
## Warning in region == c("Argentina", "Colombia", "Ecuador", "Peru", "Bolivia", :
## longitud de objeto mayor no es múltiplo de la longitud de uno menor
#Base de datos #2
s_america<-ne_countries(scale="medium",continent='south america',returnclass="sf")%>%
rename(region=sovereignt)
#Base de datos unificada
data_unificada <- suramerica %>%
left_join(s_america, by = "region")
#Map
ggplot(data_unificada, aes(x= long, y = lat,group=group, fill = pop_est))+
geom_polygon(color = "black")+
theme(axis.text.x = element_text(),
axis.text.y = element_text(),
axis.ticks = element_blank())+
labs(x="long", y="lat")+
scale_fill_distiller(palette=10)
##PuntoCinco
library(tidyverse)
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.1.3
#Base de datos
Category<-c("Alpha","Beta","Zeta")
City<-c("Hong Kong","London","Nairobi")
my_dat<-expand_grid(Category,City)
set.seed(84684)
my_dat$Value<-sample(1:10,9,replace=T)
#Gráfico
library(ggplot2)
animacion<- ggplot(my_dat, aes(x = Category, y= Value, fill= City) ) +
geom_bar(width = 0.9, stat="identity", position = position_dodge())+
labs(x="Category", y= "Value") +
labs(fill = "City")+
transition_states(City)+
enter_fade()+
exit_shrink() +
ease_aes("sine-in-out")
animacion
```