#install.packages("ggplot2")
library(ggplot2)

#install.packages("plotly")
library(plotly) #Biblioteca de gráficos interactivos
## 
## Adjuntando el paquete: '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
data("mtcars")
ggplot(data = mtcars, aes(x = wt, y = mpg)) + geom_point()

ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_point(color = "blue", size = 3) +            # Cambiar color y tamaño de los puntos
  labs(title = "Peso vs. Consumo de Combustible",  # Título del gráfico
       x = "Peso (1000 lbs)",                      # Etiqueta del eje x
       y = "Millas por Galón")                     # Etiqueta del eje y

ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  facet_grid(cyl ~ gear) 

ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  facet_grid(cyl ~ gear)

ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  facet_wrap(~ cyl, ncol = 2)+   theme_minimal()

g<-ggplot(data = mtcars, aes(x = wt, y = mpg)) +
  geom_point(aes(color = factor(cyl)), size = 3) +  # Color por número de cilindros
  labs(title = "Peso vs. Consumo de Combustible",
       x = "Peso (1000 lbs)",
       y = "Millas por Galón",
       color = "Cilindros") +                      # Leyenda de colores
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 
interactive_plot <- ggplotly(g)
interactive_plot