Primer Menú

Column

Drv

Hwy

Filter

Displ & hwy

Facet_wrap

Column

Boxplot

Boxplot (alpha)

Formulario

Shiny applications not supported in static R Markdown documents

Geom Menú

Row

Comportamiento de dataset mpg (geom_point())

Comportamiento de dataset mpg (geom_point() & shape)

Row

Comparación de eficiencia de cilindros durante el año 1999 a 2008 (facet_wrap)

Comportamiento de dataset mpg (geom_point() & size)

geom_density

Row

Mpg by tamaños y colores

Mpg

Row

Mpg usando alpha

Mpg (size & color)

---
title: "Practica Diplomado "
author: "Rouse Hernádez"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed
    
---

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

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

```



Primer Menú
=======================================================================



Column {.tabset data-width=500}
-----------------------------------------------------------------------

### **Drv** 

```{r}
p <- ggplot(mpg, aes(x = displ, y = hwy, color = drv)) + 
  geom_point() +
  geom_smooth(aes(linetype = drv))
ggplotly(p)
```


### **Hwy** 

```{r, echo=FALSE, warning=FALSE}
p <- ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point(aes(color = class)) + 
  geom_smooth()
ggplotly(p)
```


### **Filter**

```{r}
p <- ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  geom_point(
    data = mpg |> filter(class == "2seater"), 
    color = "blue"
  ) +
  geom_point(
    data = mpg |> filter(class == "2seater"), 
    shape = "circle open", size = 5, color = "red"
  )
ggplotly(p)
```

### **Displ & hwy**

```{r}

##primero pone grafica todos los puntos, 
## Despues filtra los de class = "2seater" y pinta los puntos en rojo
## Último hace el mismo filtrado pero le agrega formas, tamaño y color
p <- ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  geom_point(
    data = mpg |> filter(class == "2seater"), 
   shape = "circle open", size = 5, color = "red"
  ) +
  geom_point(
    data = mpg |> filter(class == "compact"), 
    shape = 18, size = 2, color = "blue"
  )
ggplotly(p)
```

### **Facet_wrap**
```{r}
p <- ggplot(data=mpg)+geom_jitter(aes(x=displ,y=hwy,color=drv),show.legend = FALSE) + geom_smooth(mapping = aes(x=displ,y=hwy))+
facet_wrap(. ~drv)
ggplotly(p)
```

Column {.tabset data-width=500}
-----------------------------------------------------------------------

### **Boxplot**
```{r}
ggplot(mpg, aes(class, hwy)) +
  geom_boxplot(aes(colour = class, fill = class))
```

### **Boxplot (alpha)**
```{r}
#Alpha -> Difumina el color 
ggplot(mpg, aes(class, hwy)) +
  geom_boxplot(aes(colour = class, fill = after_scale(alpha(colour, 0.4))))
```


### **Formulario**

```{r}

animals <- c("dog", "cat", "mouse", "bird", "other", "I hate animals")
# Define UI for application that draws a histogram
ui <- fluidPage(

  textInput("name", "What's your name?"),
  passwordInput("password", "What's your password?"),
  textAreaInput("story", "Tell me about yourself", rows = 3),
  selectInput("state", "What's your favourite state?", state.name),
  radioButtons("animal", "What's your favourite animal?", animals),
  radioButtons("rb", "Choose one:",
               choiceNames = list(
                 icon("angry"),
                 icon("smile"),
                 icon("sad-tear")
               ),
               choiceValues = list("angry", "happy", "sad")
  ),
  plotOutput("distPlot")
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = 40 + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'pink', border = 'white',
             xlab = 'Waiting time to next eruption (in mins)',
             main = 'Histogram of waiting times')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)
```



Geom Menú
=======================================================================

Row
-----------------------------------------------------------------------

### Comportamiento de dataset mpg (geom_point())

```{r}
##Toma la función y la pasa por pipe a ggplot
p <- mpg |> 
  ggplot(aes 
         (x = displ, y = hwy, color = class)) + 
  geom_point()
ggplotly(p)
```


### Comportamiento de dataset mpg (geom_point() & shape)

```{r}
##Shape, le da formas a los puntos salientes en la gráfica
# Right
p <- ggplot(mpg, aes(x = displ, y = hwy, shape = class)) +
  geom_point()
ggplotly(p)
```

Row
-----------------------------------------------------------------------

### Comparación de eficiencia de  cilindros  durante el año 1999 a 2008 *(facet_wrap)*

```{r}
##Se usa facet_wrap para hacer comparaciones entre grupos de distintas categorias, en este caso el año
p <- ggplot(data = mpg)+aes(x=displ,y=hwy,color=class)+geom_point()+
    facet_wrap(.~year)
ggplotly(p)
```

### Comportamiento de dataset mpg (geom_point() & size)

```{r}
# Left
p <- ggplot(mpg, aes(x = displ, y = hwy, size = displ)) +
  geom_point()
ggplotly(p)
```



geom_density
=======================================================================

Row
-----------------------------------------------------------------------

### Mpg by tamaños y colores 

```{r}
p <- ggplot(mpg, aes(x = displ, y = hwy, size = displ, color=class)) +
  geom_point()
ggplotly(p)
```

### Mpg

```{r}
p <- mpg |>
  ggplot(aes(x = displ, y = hwy)) + 
  geom_point(colour="blue")
ggplotly(p)
```

Row
-----------------------------------------------------------------------

### Mpg usando alpha

```{r}
# Right
p <- ggplot(mpg, aes(x = displ, y = hwy, alpha = displ, color = displ)) +
  geom_point()
ggplotly(p)
```

### Mpg (size & color)

```{r}
ggplot(mpg, aes(x = displ, y = hwy, size = displ, color = displ)) +
  geom_point()

```