1.Activar las librerías

library(ggplot2) #Gráficas más bonitas
library(plotly) #Gráficas interactivas
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggmap) #Mapas
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
## 
## Attaching package: 'ggmap'
## The following object is masked from 'package:plotly':
## 
##     wind

Gráfica de una función cúbica

2. Definimos un dominio x para nuestras funciones

x<-(-10:10)
x
##  [1] -10  -9  -8  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6   7   8
## [20]   9  10

3. Elegir la función que queremos graficar: j(x)=5x^3

jx<-5*x^3
plot(x,jx, main="Función cúbica", xlab="Eje x", ylab="Eje y", col="purple", type="o")

## Mapas en R

Debemos crear nuestros datos

Para realizar mapas en R, primero debemos de crear nuestros datos.

Akira<-c(-100.30925, 25.6714 )
Anahí<-c(-86.84656,21.17429)
Joyce<-c(-86.801667,21.387222)
Sveydy<-c(-103.39182,20.66682)
ubicación<-rbind(Akira,Anahí,Joyce,Sveydy)
ubicación
##              [,1]     [,2]
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Ahora que tenemos nuestros datos, cambiaremos el nombre de nuestras columnas con la función colnames:

colnames(ubicación)<-c("Longitud","Latitud")
ubicación
##          Longitud  Latitud
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Transformamos nuestra matriz en un data.frame

ubicación<-data.frame(ubicación)
ubicación
##          Longitud  Latitud
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Creamos una grafica de dispersión

dispersion<-ggplot(ubicación)+geom_text(aes(Latitud,Longitud),label= rownames(ubicación))+geom_point(aes(Latitud,Longitud),color= rainbow(4))
ggplotly(dispersion)

Creamos un mapa con la funcion qmplot

qmplot(Longitud, Latitud, data=ubicación, color=I(rainbow(4)))

Mapa de puntos y densidad

Al agregar el parámetro geom = c("point","density2d") podemos hacer un mapa de puntos y densidad:

qmplot(Longitud, Latitud, data=ubicación, geom=c("point","density2d"))

Ejemplo de aplicación

Tasa de mortalidad en México (2010-2019)

CDMX<-c(70)
Veracruz<-c(67)
Morelos<-c(67)
mortalidad<-cbind(CDMX, Veracruz, Morelos)
mortalidad
##      CDMX Veracruz Morelos
## [1,]   70       67      67
rownames(mortalidad)<-c("Tasa de mortalidad")
mortalidad
##                    CDMX Veracruz Morelos
## Tasa de mortalidad   70       67      67
x<-data.frame(mortalidad)
x
##                    CDMX Veracruz Morelos
## Tasa de mortalidad   70       67      67
x<-barplot(mortalidad)

Entidades Federativas con las mayores tasas de defunción por entidad de residencia habitual.

CDMX<-c(-99.133208, 19.4326077)
Veracruz<-c(-97.0708, 18.7289)
Morelos<-c(-99.23075, 18.9261)
ubicación<-rbind(CDMX, Veracruz, Morelos)
ubicación
##               [,1]     [,2]
## CDMX     -99.13321 19.43261
## Veracruz -97.07080 18.72890
## Morelos  -99.23075 18.92610
colnames(ubicación)<-c("Longitud","Latitud")
ubicación
##           Longitud  Latitud
## CDMX     -99.13321 19.43261
## Veracruz -97.07080 18.72890
## Morelos  -99.23075 18.92610
ubicación<-data.frame(ubicación)
ubicación
##           Longitud  Latitud
## CDMX     -99.13321 19.43261
## Veracruz -97.07080 18.72890
## Morelos  -99.23075 18.92610
dispersion<-ggplot(ubicación)+geom_text(aes(Latitud,Longitud),label=        rownames(ubicación))+geom_point(aes(Latitud,Longitud),color= rainbow(3))
ggplotly(dispersion)
qmplot(Longitud, Latitud, data=ubicación, color=I(rainbow(3)))

Este video pude ser de utilidad para entender las formulas y los comandos