-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtcarsPlotly.Rmd
76 lines (58 loc) · 2.33 KB
/
mtcarsPlotly.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: "Motor Trend Car Road Tests - Plotly"
author: "Willianto Asalim"
date: "28/07/2020"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r loadLibrary, warning=FALSE, message=FALSE}
library(plotly)
```
## Information
**Created Date: 28 July 2020**
This is a 5 web page presentation using R Markdown that features a plot on mtcars data created with Plotly. It contains an interactive table (page 3) where you can move the columns around and an interactive plot with fitted loess line (mpg~disp).
In the interactive plot on page 4:
- You can view the car info by hovering over the point.
- You can click on the legend to show/hide the data
- You can zoom in the data by using your mouse and highlight the selected area and double click to zoom out.
mtcars info: https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/mtcars.html
## Interactive mtcars data table
```{r carsTable, warning=FALSE, message=FALSE}
fig <- plot_ly(
type = 'table',
header = list(
values = c("<b>Cars</b>", names(mtcars)),
align = c('left', rep('center', ncol(mtcars))),
line = list(width = 1, color = 'black'),
fill = list(color = 'rgb(235, 100, 230)'),
font = list(family = "Arial", size = 14, color = "white")
),
cells = list(
values = rbind(
rownames(mtcars),
t(as.matrix(unname(mtcars)))
),
align = c('left', rep('center', ncol(mtcars))),
line = list(color = "black", width = 1),
fill = list(color = c('rgb(235, 193, 238)', 'rgba(228, 222, 249, 0.65)')),
font = list(family = "Arial", size = 12, color = c("black"))
))
fig
```
## Interactive mtcars Plot
```{r carsPlot, warning=FALSE, message=FALSE}
figPlot <- plot_ly(mtcars, x = ~disp, color = ~factor(cyl))
figPlot <- figPlot %>% add_markers(y = ~mpg, text = rownames(mtcars), showlegend = TRUE)
figPlot <- figPlot %>% add_lines(y = ~fitted(loess(mpg ~ disp)),
line = list(color = '#07A4B5'),
name = "Loess Smoother", showlegend = TRUE)
figPlot <- figPlot %>% layout(xaxis = list(title = 'Displacement (cu.in.)'),
yaxis = list(title = 'Miles/(US) gallon'),
legend = list(x = 0.80, y = 0.90))
figPlot
```
## Thank you!
To view my code please go to this website: https://github.com/asalimw/mtcarsPlotly
Today is **`r format(Sys.time(), '%d %B, %Y')`** and have a good day.