-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotly.Rmd
More file actions
81 lines (60 loc) · 1.72 KB
/
plotly.Rmd
File metadata and controls
81 lines (60 loc) · 1.72 KB
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
77
78
79
80
---
title: "plotly"
output: html_document
---
# Getting started with plotly
## simple graphs
```{r plotly-start, eval = F}
library(plotly)
fig <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box", height = 250)
fig
```
## fix this error/fill the missing information
```{r plotly-bar, eval = F}
fig <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "___", height = 150
)
fig
```
# Scatter plots
```{r scatter, eval = F}
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length,
height = 400,type = ___)
```
# Converting ggplots into plotly plots
```{r convert-plot, eval = F}
p <- ggplot(scorecard,
aes(x = type, y = avgfacsal)) +
geom_point(alpha = 0.5) +
stat_summary(geom = "point",
fun = "median",
color = "red", size = 5,
pch = 4, stroke = 2)
g___
```
## Dot plots
```{r, eval = F}
p <- ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) +
geom_dotplot(stackgroups = TRUE, binwidth = 1, binpositions = "all")
ggplotly(p, height = 325)
```
---
## Barbel/Dumbell plots
```{r plotly-dumbell, eval = F}
gapminder <- read_csv("https://raw.githubusercontent.com/datavizpyr/data/master/gapminder-FiveYearData.csv")
df <- gapminder %>%
filter(year %in% c(1952,2007)) %>%
filter(continent=="Asia")
df <- df %>%
mutate(paired = rep(1:(n()/2),each=2),
year=factor(year))
p <- df %>% group_by(paired) %>%
ggplot(aes(x= lifeExp, y= reorder(country,lifeExp))) +
geom_line(aes(group = paired),color="grey")+
geom_point(aes(color=year), size=2) + scale_color_viridis_d(name = "Year", option = "turbo") +
labs(y="country") + theme(text = element_text(size = 10))
g___
```