Row

Gráfica dinámica de puntos

Row

Gráfica dinámica de barras

Row

Chart C

chart D

Chart E

Row

Chart F

Chart G

Row

Chart G

Chart H

Row

Chart I

Chart j

Row

Chart K

Chart L

Row

Chart M

Chart N

Row

Chart O

Chart P

Chart Q

Row

Chart R

Chart S

Row

Chart U

Chart V

Chart X

Row

Chart y

Chart z

Row

Chart AA

Chart AB

Row

Chart AC

Chart AD

Row

Chart AE

Chart AF

Row

Chart AG

Chart AH

Row

Chart AI

---
title: "Examen de Amilcar Sosa"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(shiny)
library(ggplot2)
library(mgcv)
library(flexdashboard)
library(tidyverse)




mpg_temp_001 <- mpg
dataset <- mpg_temp_001 %>% rename(
    fabricante = manufacturer,
    modelo = model)
mpg_temp_002 = dataset

```

Inputs {.sidebar}
-----------------------------------------------------------------------

```{r}
sliderInput('sampleSize', 'Número de datos', min=1, max=nrow(dataset),
            value=min(100, nrow(dataset)), step=20, round=0)

checkboxInput('jitter', 'Jitter', value = TRUE)
checkboxInput('smooth', 'Smooth', value = TRUE)

selectInput('x', 'X', names(dataset))
selectInput('y', 'Y', names(dataset), names(dataset)[[2]])
selectInput('color', 'Color', c('Ninguno', names(dataset)))

selectInput('facet_row', 'Fila de facetas',
            c(None='.', names(mpg_temp_002)))
selectInput('facet_col', 'Columnasde facetas',
            c(None='.', names(mpg_temp_002), selected = colnames(mpg_temp_002)[2]))

```



Row {data-height=800}
-----------------------------------------------------------------------

### Gráfica dinámica de puntos

```{r , echo=FALSE, warning=FALSE, error=FALSE,}

dataset <- reactive({
  mpg_temp_002[sample(nrow(mpg_temp_002), input$sampleSize),]
})


renderPlot({
  p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_point()
  
  if (input$color != 'Ninguno')
    p <- p + aes_string(color=input$color)
  
  facets <- paste(input$facet_row, '~', input$facet_col)
  if (facets != '. ~ .')
    p <- p + facet_grid(facets)
  
  if (input$jitter)
    p <- p + geom_jitter()
  if (input$smooth)
    p <- p + geom_smooth()
  
  print(p)
})

```

Row {data-height=800}
-----------------------------------------------------------------------

### Gráfica dinámica de barras

```{r , echo=FALSE, warning=FALSE, error=FALSE,}

renderPlot({
  c <- ggplot(dataset(), aes_string(x=input$x)) + geom_bar()
  
  if (input$color != 'Ninguno')
    c <- c + aes_string(fill=input$color)
  
  print(c)
})

```

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

### Chart C

```{r , echo=FALSE, warning=FALSE, error=FALSE,}
mpg |>
  ggplot()+
  geom_point(aes(x = displ, y = hwy, color = class))
```

### chart D

```{r , echo=FALSE, warning=FALSE, error=FALSE,}
# Right
ggplot(mpg, aes(x = displ, y = hwy, shape = class)) +
  geom_point()
```

### Chart E

```{r}


ggplot(mpg) + 
  geom_point(aes(x = displ, y = hwy, color = "blue"))

```

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

### Chart F

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


### Chart G

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

```


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


### Chart G

```{r}

ggplot(mpg, aes(x = displ, y = hwy, size = displ)) +
  geom_point()

```



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


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


### Chart I
```{r}

ggplot(mpg, aes(x = displ, y = hwy, size = displ, color=displ)) +
  geom_point()

```




### Chart j
```{r}
# Right
ggplot(mpg, aes(x = displ, y = hwy, alpha = displ)) +
  geom_point()
```


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


### Chart K
```{r}
# Right
ggplot(mpg, aes(x = displ, y = hwy, alpha = displ, color=displ)) +
  geom_point()
```



### Chart L
```{r}
mpg |>
  ggplot(aes(x = displ, y = hwy)) + 
  geom_point(colour="blue")
```



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

### Chart M
```{r}

ggplot(mpg, aes(x = displ, y = hwy, color = drv)) + 
  geom_point() +
  geom_smooth(aes(linetype = drv))

```




### Chart N
```{r}

ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point(aes(color = class)) + 
  geom_smooth()

```


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


### Chart O
```{r}
ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  geom_point(
    data = mpg |> dplyr::filter(class == "2seater"), 
    color = "red"
  ) +
  geom_point(
    data = mpg |> dplyr::filter(class == "2seater"), 
    shape = "circle open", size = 5, color = "red"
  )
```



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



### Chart Q
```{r}
ggplot(mpg, aes(class, hwy)) +
  geom_boxplot(aes(colour = class, fill = after_scale(alpha(colour, 0.4))))
```



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

### Chart R
```{r}
# Making a proportional stacked density plot
ggplot(mpg, aes(cty)) +
  geom_density(
    aes(
      colour = factor(cyl),
      fill = after_scale(alpha(colour, 0.3)),
      y = after_stat(count / sum(n[!duplicated(group)]))
    ),
    position = "stack", bw = 1
  ) +
  geom_density(bw = 1)
```



### Chart S
```{r}
# Imitating a ridgeline plot
ggplot(mpg, aes(cty, colour = factor(cyl))) +
  geom_ribbon(
    stat = "density", outline.type = "upper",
    aes(
      fill = after_scale(alpha(colour, 0.3)),
      ymin = after_stat(group),
      ymax = after_stat(group + ndensity)
    )
  )
```

```{r}
library(ggridges)
```

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



### Chart U
```{r}
ggplot(mpg, aes(x = hwy, y = drv, fill = drv, color = drv)) +
  geom_density_ridges(alpha = 0.5, show.legend = FALSE)
#> Picking joint bandwidth of 1.28
```



### Chart V
```{r}
ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  facet_wrap(~cyl)
```



### Chart X
```{r}
ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  facet_grid(drv ~ cyl)
```

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



### Chart y
```{r}
ggplot(mpg, aes(x = displ, y = hwy)) + 
  geom_point() + 
  facet_grid(drv ~ cyl, scales = "free_y")
```



### Chart z
```{r}
ggplot(mpg) + 
  geom_point(aes(x = displ, y = hwy)) +
  facet_grid(drv ~ .)
```

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



### Chart AA
```{r}
ggplot(mpg) + 
  geom_point(aes(x = displ, y = hwy)) +
  facet_grid(. ~ cyl)
```



### Chart AB
```{r}
ggplot(mpg) + 
  geom_point(aes(x = displ, y = hwy)) + 
  facet_wrap(~ class, nrow = 2)
```


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


### Chart AC
```{r}
# Left
ggplot(mpg, aes(x = drv, color = drv)) + 
  geom_bar()


```



### Chart AD
```{r}
# Right
ggplot(mpg, aes(x = drv, fill = drv)) + 
  geom_bar()
```


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


### Chart AE
```{r}
ggplot(mpg, aes(x = drv, fill = class)) + 
  geom_bar()
```



### Chart AF
```{r}
ggplot(mpg, aes(x = drv, fill = class)) + 
  geom_bar(alpha = 1/2, position = "identity")
```

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




### Chart AG
```{r}
# Right
ggplot(mpg, aes(x = drv, color = class)) + 
  geom_bar(fill = NA, position = "identity")
```




### Chart AH
```{r}
# Left
ggplot(mpg, aes(x = drv, fill = class)) + 
  geom_bar(position = "fill")


```


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


### Chart AI
```{r}
# Right
ggplot(mpg, aes(x = drv, fill = class)) + 
  geom_bar(position = "dodge")
```