---
title: "Bar Charts"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: spacelab
navbar:
- { icon: "fa-facebook", href: "https://bit.ly/3pz450p", align: right }
- { icon: "fa-twitter", href: "https://twitter.com/RHablamos", align: right }
- { icon: "fa-linkedin", href: "https://bit.ly/3pyxAzw", align: right }
- { icon: "fa-github", href: "https://bit.ly/3T3h1Jy", align: right }
source: embed
---
```{r setup, include=FALSE}
library(ggplot2)
library(lattice)
library(flexdashboard)
```
BarCharts_01 {data-navmenu="Menu A"}
=========================================================================
Column {data-width=333}
-----------------------------------------------------------------------
### barplot()
```{r}
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}
ggplot(mtcars,aes(cyl)) + geom_bar(fill=colores) + labs(x="Cillindros",y="Frecuencias",title="Número de Cilindros") + theme_dark()
```
Column {data-width=333}
------------------------------------------------------------------------
### lattice
```{r}
barchart(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores,horizontal=FALSE)
```
Bar_Charts_02 {data-navmenu="Menu A"}
=========================================================================
Column {data-width=500}
----------------------------------------------------------------------
### mtcars_cyl
```{r}
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=500}
----------------------------------------------------------------------
### mtcars_cyl_gear
```{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))
```
Bar_Charts_03 {data-navmenu="Menu B"}
=======================================================================
### Diagrama Barras
```{r}
barchart(x,xlab="Cilindros",ylab="Frecuencias",main="Número de Cilindros",col=colores,horizontal=FALSE)
```
Bar_Charts_04 {data-navmenu="Menu B"}
=========================================================================
## {.tabset .tabset-fade}
### 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")
```
### 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 Líneas
```{r}
x <- c(1, 2, 3, 4, 5)
y <- c(200, 300, 600, 700, 500)
# Vectores
plot(x, y, type = "l")
```