Análisis Exploratorio de Datos

Row

---
title: "Analisis de Datos"
Autor: "Ramona Moranchel Morales"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed

#  pdf_document: default
 # word_document: default
  #html_notebook: default
  
---
## Análisis Exploratorio de Datos

```{r setup, include=FALSE}
library(tidyverse)
library(highcharter)
library(ggplot2)
library(plotly)
library(plyr)
library(dplyr)
library(viridisLite)
library(forecast)
library(treemap)
library(arules)
library(flexdashboard)

thm <- 
  hc_theme(
    colors = c("#1a6ecc", "#434348", "#90ed7d"),
    chart = list(
      backgroundColor = "transparent",
      style = list(fontFamily = "Source Sans Pro")
    ),
    xAxis = list(
      gridLineWidth = 1
    )
  )


```
```{r discripcion-variables, eval=FALSE, echo=FALSE}

str(diamonds)
```
Row

```{r}
# left
p <- ggplot(diamonds, aes(x = price)) +
  geom_histogram(binwidth = 500) + theme(panel.grid.major = element_line(color = "green", size = 0.8),
        panel.grid.minor = element_line(color = "lightgray", size = 0.5, linetype = "dotted")) +
  labs(
title = "Precio de los diamantes"
)
ggplotly (p)
```
```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(shape=5)+  theme(axis.text = element_text(color = "blue"))+ 
  labs(
title = "precio frente al quilataje"
)

```
```{r}
p <- ggplot(diamonds, aes(x = price)) +
  geom_histogram(binwidth = 500, fill = "blue", color = "black") +
  theme_minimal() +
  labs(title = "Distribución de Precios de Diamantes",
       x = "Precio",
       y = "Frecuencia")

ggplotly(p)
```
```{r}
p <- ggplot(diamonds, aes(x = cut, y = price, fill = cut)) +
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Precio Promedio por Corte",
       x = "Corte",
       y = "Precio")

ggplotly(p)
```
```{r}
p <- ggplot(diamonds, aes(x = color, y = price)) +
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Precio Promedio por Color",
       x = "Color",
       y = "Precio")

ggplotly(p)
```
```{r}
p <- ggplot(diamonds, aes(x = carat)) +
  geom_histogram(binwidth = 0.1, fill = "green", color = "black") +
  theme_minimal() +
  labs(title = "Distribución de Carat de Diamantes",
       x = "Carat",
       y = "Frecuencia")

ggplotly(p)
```
```{r}
p <- ggplot(diamonds, aes(x = depth)) +
  geom_histogram(binwidth = 0.2, fill = "purple", color = "black") +
  theme_minimal() +
  labs(title = "Distribución de Profundidad de Diamantes",
       x = "Profundidad",
       y = "Frecuencia")

ggplotly(p)
```
```{r}
p <- ggplot(diamonds, aes(x = color, y = price, fill = clarity)) +
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Precio Promedio por Color y Claridad",
       x = "Color",
       y = "Precio")

ggplotly(p)
```

```{r}
ggplot(diamonds, aes(x = cut)) +
  geom_bar()+ 
  labs(
    title = " calidad del corte"
)

```
```{r}
ggplot(diamonds, aes(x = clarity, y = price)) +
  geom_boxplot(color="firebrick")+
  labs( 
title = "precio según la claridad"
)
```
```{r}
diamonds |> ggplot(aes(x = carat)) +
  geom_histogram(binwidth = 0.2)+ theme(panel.background = element_rect(fill = "lightblue"),
        panel.grid.major = element_line(color = "white", size = 0.5),
        panel.grid.minor = element_line(color = "lightgray", size = 0.25)) + 
  labs(
title = "corte segun los quilates"
)
```
```{r}
ggplot(diamonds, aes(x = price)) +
  geom_histogram(binwidth = 500, fill = "skyblue", color = "black") +
  labs(title = "Histograma del precio de los diamantes", x = "Precio", y = "Frecuencia")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(color = "purple") +  theme_linedraw() + 
  labs(title = "Diagrama de dispersión del precio vs. quilataje", x = "Quilataje", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = cut, fill = cut)) +
  geom_bar() + 
  labs(title = "Gráfico de barras de la calidad del corte", x = "Calidad del corte", y = "Conteo") +  geom_hline(yintercept = 10000, color = "red", linetype = "dashed") +
  geom_vline(xintercept = 1, color = "blue", linetype = "dotted") +
  theme(legend.position = "none")
```
```{r}
ggplot(diamonds, aes(x = clarity, y = price, fill = clarity)) +
  geom_boxplot() +
  labs(title = "Diagrama de caja del precio según la claridad", x = "Claridad", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.5) +
  labs(title = "Gráfico de densidad del precio de los diamantes", x = "Precio", y = "Densidad") +
  scale_fill_brewer(palette = "Set1")
```
```{r}
ggplot(diamonds, aes(x = color, fill = clarity)) +
  geom_bar() +
  labs(title = "Gráfico de barras apiladas del precio según color y claridad", x = "Color", y = "Precio") +
  theme(legend.position = "bottom")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price, color = color)) +
  geom_point(shape=11, size=2)+
  labs(title = "Diagrama de dispersión del precio vs. quilataje (coloreado por color)", x = "Quilataje", y = "Precio")
```

```{r}
diamonds_avg_price_by_cut <- aggregate(price ~ cut, data = diamonds, FUN = mean)
ggplot(diamonds_avg_price_by_cut, aes(x = cut, y = price)) +
  geom_bar(stat = "identity", fill = "orange") +  theme(panel.background = element_rect(fill = "lightyellow", color = "black"))+ theme(axis.text = element_text(color = "blue")) +
  labs(title = "Precio promedio por calidad de corte", x = "Calidad de corte", y = "Precio promedio")
```
```{r}
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.9) +
  labs(title = "Gráfico de densidad del precio de los diamantes por tipo de corte", x = "Precio", y = "Densidad") +
  scale_fill_brewer(palette = "Dark2")
```
```{r}
ggplot(diamonds, aes(x = cut, fill = color)) +
  geom_bar() +
  labs(title = "Número de diamantes por tipo de corte y color", x = "Tipo de corte", y = "Conteo") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r}
ggplot(diamonds, aes(x = cut, y = price, fill = color)) +
  geom_boxplot() +
  labs(title = "Diagrama de caja del precio según tipo de corte y color", x = "Tipo de corte", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(stat = "identity", colour = "red" , size = 2, shape= 20) +
  facet_wrap(~color) +
  labs(title = "Diagrama de dispersión del precio vs. quilataje (facetado por color)", x = "Quilataje", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.5) +
  facet_wrap(~clarity) +
  labs(title = "Gráfico de densidad del precio de los diamantes por tipo de corte y claridad", x = "Precio", y = "Densidad") +
  scale_fill_brewer(palette = "Paired")
```
```{r}
diamonds_avg_price_by_cut_clarity <- aggregate(price ~ cut + clarity, data = diamonds, FUN = mean)
ggplot(diamonds_avg_price_by_cut_clarity, aes(x = cut, y = price, fill = clarity)) +
  geom_bar(stat = "identity") +
  labs(title = "Precio promedio por tipo de corte y claridad", x = "Tipo de corte", y = "Precio promedio") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r}
ggplot(diamonds, aes(x = cut, y = price, fill = color)) +
  geom_bar(stat = "summary", fun = "mean") +
  labs(title = "Precio promedio de los diamantes por tipo de corte y color", x = "Tipo de corte", y = "Precio promedio")
```
```{r}
diamonds_avg_price_by_cut_color <- aggregate(price ~ cut + color, data = diamonds, FUN = mean)
diamonds_avg_price_by_cut_color <- diamonds_avg_price_by_cut_color[order(diamonds_avg_price_by_cut_color$price), ]
ggplot(diamonds_avg_price_by_cut_color, aes(x = cut, y = price, fill = color)) +
  geom_bar(stat = "identity") +
  labs(title = "Precio promedio por tipo de corte y color (ordenado por precio)", x = "Tipo de corte", y = "Precio promedio") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r}
ggplot(diamonds, aes(x = price)) +
  geom_histogram(binwidth = 200, fill = "green", color = "black") +
  labs(title = "Distribución del Precio de los Diamantes", x = "Precio", y = "Frecuencia")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(alpha = 0.3, color = "red" , shape= 2 ) +
  labs(title = "Relación entre Carat y Precio", x = "Carat", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = cut, y = price)) +
  geom_boxplot(fill = "lightblue") +
  labs(title = "Boxplot del Precio por Corte", x = "Corte", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = carat, fill = clarity)) +
  geom_density(alpha = 0.5) +
  labs(title = "Distribución del Peso (Carat) por Claridad", x = "Carat", y = "Densidad")
```
```{r}
ggplot(diamonds, aes(x = clarity, y = price)) +
  geom_boxplot(fill = "pink") +
  labs(title = "Relación entre Precio y Claridad", x = "Claridad", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(alpha = 0.9, color = "pink") +
  facet_wrap(~ cut) +
  labs(title = "Relación entre Carat y Precio por Corte", x = "Carat", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = carat)) +
  geom_histogram(binwidth = 0.10, fill = "purple", color = "black") +
  labs(title = "Distribución del Peso de los Diamantes (Carat)", x = "Carat", y = "Frecuencia")
```
```{r}
ggplot(diamonds, aes(x = color, y = price)) +
  geom_boxplot(fill = "lightblue") +
  labs(title = "Boxplot del Precio por Color", x = "Color", y = "Precio")
```
```{r}
p <- ggplot(diamonds, aes(x = table, y = price)) +
  geom_point(shape = 21, stroke = 1, color = "blue") +
  labs(title = "Relación entre Precio y Tabla", x = "Tabla", y = "Precio")
ggplotly(p)
```
```{r}
ggplot(diamonds, aes(x = depth, y = price)) +
  geom_point(alpha = 0.15, color = "orange") +
  labs(title = "Relación entre Precio y Profundidad", x = "Profundidad", y = "Precio")
```

```{r}
ggplot(diamonds, aes(x = carat, y = price)) +
  geom_point(alpha = 0.2, color = "purple") +
  facet_wrap(~ clarity) +
  labs(title = "Relación entre Precio y Carat por Claridad", x = "Carat", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = price, fill = color)) +
  geom_histogram(binwidth = 500, position = "dodge") +
  labs(title = "Distribución del Precio por Color", x = "Precio", y = "Frecuencia")
```
```{r}
ggplot(diamonds, aes(x = price, fill = clarity)) +
  geom_histogram (binwidth = 900, position = "Dodge") +
  labs(title = "Distribución del Precio por Claridad", x = "Precio", y = "Frecuencia")
```
```{r}
ggplot(diamonds, aes(x = cut, y = price, fill = color)) +
  geom_jitter() +
  labs(title = "Boxplot del Precio por Corte y Color", x = "Corte", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = cut, y = price, fill = clarity)) +
  geom_violin() +
  labs(title = "Boxplot del Precio por Corte y Claridad", x = "Corte", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = depth, y = price, color = color)) +
  geom_point(alpha = 0.5) +
  labs(title = "Relación entre Precio y Profundidad por Color", x = "Profundidad", y = "Precio")
```
```{r}
ggplot(diamonds, aes(x = carat, y = price, fill = color)) +
  geom_contour_filled(stat = "identity", position = "dodge") +
  labs(title = "Precio Promedio por Carat y Color", x = "Carat", y = "Precio Promedio")
```
```{r}
ggplot(diamonds, aes(x = color, y = price, fill = clarity)) +
  geom_raster() +
  labs(title = "Boxplot del Precio por Color y Claridad", x = "Color", y = "Precio")
```