Skip to content

Commit 0e535a3

Browse files
author
Joseph Damiba
committed
adding more files
1 parent 80a8561 commit 0e535a3

28 files changed

+3197
-0
lines changed

r/2015-07-30-2D-Histogram.Rmd

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
name: 2D Histograms
3+
permalink: r/2D-Histogram/
4+
description: How to make a 2D histogram in R. A 2D histogram is a visualization of a bivariate distribution.
5+
layout: base
6+
thumbnail: thumbnail/histogram2d.jpg
7+
language: r
8+
page_type: example_index
9+
display_as: statistical
10+
order: 1
11+
output:
12+
html_document:
13+
keep_md: true
14+
---
15+
16+
```{r, echo = FALSE, message=FALSE}
17+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
18+
```
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
```{r}
31+
library(plotly)
32+
packageVersion('plotly')
33+
```
34+
35+
#### Basic 2D Histogram
36+
37+
2D histograms require `x`/`y`, but in contrast to heatmaps, `z` is optional. If `z` is not provided, binning occurs in the browser (see [here](https://plot.ly/r/reference/#histogram2d-histnorm) for a list of binning options).
38+
39+
```{r}
40+
# install.packages('mvtnorm')
41+
library(plotly)
42+
43+
s <- matrix(c(1, -.75, -.75, 1), ncol = 2)
44+
obs <- mvtnorm::rmvnorm(500, sigma = s)
45+
p <- plot_ly(x = obs[,1], y = obs[,2])
46+
pp <- subplot(
47+
p %>% add_markers(alpha = 0.2),
48+
p %>% add_histogram2d()
49+
)
50+
51+
pp
52+
```
53+
54+
#### Colorscale
55+
If `z` is not provided, the only way to control coloring is through the [colorscale attribute](https://plot.ly/r/reference/#histogram2d-colorscale)
56+
57+
```{r}
58+
p <- p %>% add_histogram2d(colorscale = "Blues")
59+
60+
p
61+
```
62+
63+
#### Z Matrix
64+
If you want more control for the binning algorithm, you can supply a 2D table or matrix to `z`. In this case, the R package will impose it's colorscale default (and the `colors` argument can be used to control the colorscale from R):
65+
66+
```{r}
67+
cnt <- with(diamonds, table(cut, clarity))
68+
p <- plot_ly(diamonds, x = ~cut, y = ~clarity, z = ~cnt) %>%
69+
add_histogram2d()
70+
71+
p
72+
```

r/2015-07-30-LaTeX.Rmd

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: LaTeX Typesetting in R Graphs
3+
permalink: r/LaTeX/
4+
description: How to add LaTeX to R graphs.
5+
layout: base
6+
thumbnail: thumbnail/latex.jpg
7+
language: r
8+
page_type: example_index
9+
display_as: style_opt
10+
order: 4
11+
output:
12+
html_document:
13+
keep_md: true
14+
---
15+
16+
```{r, echo = FALSE, message=FALSE}
17+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
18+
```
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
```{r}
31+
library(plotly)
32+
packageVersion('plotly')
33+
```
34+
35+
#### LaTeX Typesetting
36+
37+
38+
```{r}
39+
library(plotly)
40+
p <- plot_ly(
41+
x = c(1, 2, 3, 4),
42+
y = c(1, 4, 9, 16),
43+
name = TeX("\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}")) %>%
44+
add_trace(
45+
x = c(1, 2, 3, 4),
46+
y = c(0.5, 2, 4.5, 8),
47+
name = TeX("\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}")) %>%
48+
layout(
49+
xaxis = list(
50+
title = TeX("\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}")),
51+
yaxis = list(
52+
title = TeX("d, r \\text{ (solar radius)}"))) %>%
53+
config(mathjax = 'cdn')
54+
55+
p
56+
```
57+
58+
#### Reference
59+
60+
For more information about LaTeX, [click here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd).

r/2015-07-30-box-plots.Rmd

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
name: Box Plots
3+
permalink: r/box-plots/
4+
description: How to make an interactive box plot in R. Examples of box plots in R that are grouped, colored, and display the underlying data distribution.
5+
layout: base
6+
thumbnail: thumbnail/box.jpg
7+
language: r
8+
page_type: example_index
9+
display_as: statistical
10+
order: 2
11+
output:
12+
html_document:
13+
keep_md: true
14+
---
15+
16+
```{r, echo = FALSE, message=FALSE}
17+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
18+
```
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
```{r}
31+
library(plotly)
32+
packageVersion('plotly')
33+
```
34+
35+
### Basic Boxplot
36+
37+
```{r}
38+
library(plotly)
39+
p <- plot_ly(y = ~rnorm(50), type = "box") %>%
40+
add_trace(y = ~rnorm(50, 1))
41+
42+
p
43+
```
44+
45+
### Horizontal Boxplot
46+
47+
```{r}
48+
library(plotly)
49+
p <- plot_ly(x = ~rnorm(50), type = "box") %>%
50+
add_trace(x = ~rnorm(50, 1))
51+
52+
p
53+
```
54+
55+
### Adding Jittered Points
56+
57+
```{r}
58+
p <- plot_ly(y = ~rnorm(50), type = "box", boxpoints = "all", jitter = 0.3,
59+
pointpos = -1.8)
60+
61+
p
62+
```
63+
64+
65+
### Several Box Plots
66+
67+
```{r}
68+
p <- plot_ly(ggplot2::diamonds, y = ~price, color = ~cut, type = "box")
69+
70+
p
71+
```
72+
73+
### Grouped Box Plots
74+
75+
```{r}
76+
p <- plot_ly(ggplot2::diamonds, x = ~cut, y = ~price, color = ~clarity, type = "box") %>%
77+
layout(boxmode = "group")
78+
79+
p
80+
```
81+
82+
### Styling Outliers
83+
84+
```{r}
85+
library(plotly)
86+
87+
y1 <- c(0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
88+
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25)
89+
y2 <- c(0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
90+
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25)
91+
y3 <- c(0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
92+
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25)
93+
y4 <- c(0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
94+
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25)
95+
96+
p <- plot_ly(type = 'box') %>%
97+
add_boxplot(y = y1, jitter = 0.3, pointpos = -1.8, boxpoints = 'all',
98+
marker = list(color = 'rgb(7,40,89)'),
99+
line = list(color = 'rgb(7,40,89)'),
100+
name = "All Points") %>%
101+
add_boxplot(y = y2, name = "Only Whiskers", boxpoints = FALSE,
102+
marker = list(color = 'rgb(9,56,125)'),
103+
line = list(color = 'rgb(9,56,125)')) %>%
104+
add_boxplot(y = y3, name = "Suspected Outlier", boxpoints = 'suspectedoutliers',
105+
marker = list(color = 'rgb(8,81,156)',
106+
outliercolor = 'rgba(219, 64, 82, 0.6)',
107+
line = list(outliercolor = 'rgba(219, 64, 82, 1.0)',
108+
outlierwidth = 2)),
109+
line = list(color = 'rgb(8,81,156)')) %>%
110+
add_boxplot(y = y4, name = "Whiskers and Outliers", boxpoints = 'outliers',
111+
marker = list(color = 'rgb(107,174,214)'),
112+
line = list(color = 'rgb(107,174,214)')) %>%
113+
layout(title = "Box Plot Styling Outliers")
114+
115+
p
116+
```
117+
118+
### Reference
119+
120+
See [https://plot.ly/r/reference/#box](https://plot.ly/r/reference/#box) for more information and chart attribute options!

r/2015-07-30-histograms.Rmd

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
name: Histograms
3+
permalink: r/histograms/
4+
description: How to make a histogram in R.
5+
layout: base
6+
thumbnail: thumbnail/histogram.jpg
7+
language: r
8+
page_type: example_index
9+
display_as: statistical
10+
order: 3
11+
output:
12+
html_document:
13+
keep_md: true
14+
---
15+
16+
```{r, echo = FALSE, message=FALSE}
17+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
18+
```
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
```{r}
31+
library(plotly)
32+
packageVersion('plotly')
33+
```
34+
35+
#### Basic Histogram
36+
37+
```{r}
38+
library(plotly)
39+
p <- plot_ly(x = ~rnorm(50), type = "histogram")
40+
41+
p
42+
```
43+
44+
#### Normalized Histogram
45+
46+
```{r}
47+
library(plotly)
48+
p <- plot_ly(x = ~rnorm(50),
49+
type = "histogram",
50+
histnorm = "probability")
51+
52+
p
53+
```
54+
55+
#### Specify Binning Function
56+
57+
```{r}
58+
library(plotly)
59+
60+
x = c("Apples","Apples","Apples","Organges", "Bananas")
61+
y = c("5","10","3","10","5")
62+
63+
p <- plot_ly(y=y, x=x, histfunc='sum', type = "histogram") %>%
64+
layout(yaxis=list(type='linear'))
65+
66+
p
67+
```
68+
69+
#### Horizontal Histogram
70+
71+
```{r}
72+
library(plotly)
73+
p <- plot_ly(y = ~rnorm(50), type = "histogram")
74+
75+
p
76+
```
77+
78+
#### Overlaid Histograms
79+
80+
```{r}
81+
p <- plot_ly(alpha = 0.6) %>%
82+
add_histogram(x = ~rnorm(500)) %>%
83+
add_histogram(x = ~rnorm(500) + 1) %>%
84+
layout(barmode = "overlay")
85+
86+
p
87+
```
88+
89+
#### Stacked Histograms
90+
91+
```{r}
92+
p <- plot_ly(alpha = 0.6) %>%
93+
add_histogram(x = ~rnorm(500)) %>%
94+
add_histogram(x = ~rnorm(500) + 1) %>%
95+
layout(barmode = "overlay")
96+
97+
p
98+
```
99+
100+
#### Cumulative Histogram
101+
102+
```{r}
103+
library(plotly)
104+
p <- plot_ly(x = ~rnorm(50),
105+
type = "histogram",
106+
cumulative = list(enabled=TRUE))
107+
108+
p
109+
```
110+
111+
### Reference
112+
113+
See [https://plot.ly/r/reference/#histogram](https://plot.ly/r/reference/#histogram) for more information and chart attribute options!

0 commit comments

Comments
 (0)