---
title: "Bar Charts"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: united
navbar:
- { icon: "fa-facebook", href: "https://bit.ly/3pz450p", target: "_blank", align: right }
- { icon: "fa-twitter", href: "https://twitter.com/RHablamos", target: "_blank", align: right }
- { icon: "fa-linkedin", href: "https://bit.ly/3pyxAzw", target: "_blank", align: right }
- { icon: "fa-github", href: "https://bit.ly/3T3h1Jy", target: "_blank", align: right }
source: embed
---
```{r setup, include=FALSE}
library(ggplot2)
library(lattice)
library(flexdashboard)
```
# BarCharts_01 {data-icon=fa-bar-chart}
Column {data-width=333}
-----------------------------------------------------------------------
### barplot()
```{r barplot,fig.align='center'}
x <- table(mtcars$cyl)
colores <- c("orange","blue","purple")
barplot(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores)
```
Column {data-width=333}
-----------------------------------------------------------------------
### ggplot2
```{r ggplot2,fig.align='center'}
ggplot(mtcars,aes(cyl)) + geom_bar(fill=colores) + labs(x="Cillindros",y="Frecuencias",title="Número de Cilindros") + theme_dark()
```
Colum {data-width=333}
------------------------------------------------------------------------
### lattice
```{r lattice,fig.align='center'}
barchart(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores,horizontal=FALSE)
```
# Bar_Charts_02 {data-icon=fa-bar-chart}
Column {data-width=500}
--------------------------------------------------------------------------
### mtcars_gear
```{r}
y <- table(mtcars$gear)
barplot(y,xlab="Engranajes",ylab="Frecuencias",main="Número de Engranajes",col=rainbow(3))
```
Column {data-width=500}
--------------------------------------------------------------------------
### mtcars_cyl_gear
```{r}
par(mfrow=c(1,2))
barplot(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores)
barplot(y,xlab="Engranajes",ylab="Frecuencias",main="Número de Engranajes",col=rainbow(3))
```
# Bar_Charts_03
### mtcars_cyl
```{r}
ggplot(mtcars,aes(cyl)) + geom_bar(fill=colores) + labs(x="Cillindros",y="Frecuencias",title="Número de Cilindros") + theme_dark()
```
# Bar_Charts_04
## {.tabset}
### Bar Chart
```{r}
y <- table(mtcars$gear)
par(mfrow=c(1,2))
barplot(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores)
barplot(y,xlab="Engranajes",ylab="Frecuencias",main="Número de Engranajes",col=rainbow(3))
```
### Pie Chart
```{r}
porcentaje <- c(15.59,8.88,6.66,13.33,11.11,17.77,26.66)
etiqueta <- paste(porcentaje,"%",sep=" ")
colores <- c("purple","orange","blue","yellow","green","skyblue","pink")
pie(porcentaje,labels = etiqueta,clockwise = TRUE,col = colores,
main = "Gustos musicales de los Estudiantes de Estadística 101")
legend("topright",c("Cumbia","Eletrónica","Hip Hop","Latin","Pop","Rock","Salsa"),cex=0.5,
fill= colores)
```
### Gráfico de Líneas
```{r}
# Datos
x <- c(1, 2, 3, 4, 5)
y <- c(200, 300, 600, 700, 500)
# Vectores
plot(x, y, type = "l")
```
### Histograma
```{r}
distancia <- c(241.1, 284.4, 220.2, 272.4, 271.1, 268.3,
291.6, 241.6, 286.1, 285.9, 259.6, 299.6,
253.1, 239.6, 277.8, 263.8, 267.2, 272.6,
283.4, 234.5, 260.4, 264.2, 295.1, 276.4,
263.1, 251.4, 264.0, 269.2, 281.0, 283.2)
hist(distancia, main = "Histograma de frecuencias", # Frecuencia
ylab = "Frecuencia")
```