---
title: "Tables (HTML output)"
author: "Katia Bulekova"
date: "`r Sys.Date()`"
output:
html_document:
toc: true
number_sections: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```
Let's prepare the datasets we will use in this notebook:
```{r}
library(tidyverse)
data(mtcars)
data(mpg)
mtcars2 <- mtcars
mtcars2$am <- factor(
mtcars$am, labels = c('automatic', 'manual')
)
```
Let's plot a simple graph using ggplot2 package:
```{r}
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() + geom_smooth() +
theme(legend.position = 'bottom')
```
*****
Chunk options allow us to control the dimentions of the output plot:
```{r, fig.width=4, fig.height=3}
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() + geom_smooth() +
theme(legend.position = 'bottom')
```
*****
If we want the plot to dynamically change its size, we can specify the width in percentages:
```{r, out.width="60%"}
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() + geom_smooth() +
theme(legend.position = 'bottom')
```
# Hicharter
[Highchirter package](https://jkunst.com/highcharter/) is an R wrapper for a *Highcharts* javascript library.
```{r, warning=FALSE, message=FALSE}
library(highcharter)
```
## Histogram
```{r}
hchart(mtcars$mpg, name = "MPG", color = "#17b8b6")
```
## Barplot
```{r}
mtcars2 %>%
count(am) %>%
hchart('column', hcaes(x = am, y = n))
```
[More examples](https://rpubs.com/techanswers88/highcharterBarChart)
# dygraphs
[Dygraphs gallery and documentation](https://rstudio.github.io/dygraphs/)
This library is most useful to display time-series data:
```{r, warning=FALSE, message=FALSE}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths)
```
***********
# plotly
[Plotly R Library](https://plotly.com/r/plotly-fundamentals/)
This library is easy to use if you are familiar with ggplot2 library:
```{r, warning=FALSE, message=FALSE}
library(plotly)
g <- ggplot(mpg, aes(class))
p <- g + geom_bar(aes(fill = drv))
ggplotly(p)
```