8000 Merge pull request #37 from plotly/bingroup · plotly/plotly.r-docs@2debb5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2debb5b

Browse files
authored
Merge pull request #37 from plotly/bingroup
bingroup
2 parents cb7074f + ac85b9c commit 2debb5b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

r/2015-07-30-histograms.Rmd

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,47 @@ fig <- plot_ly(x = ~rnorm(50),
9191
9292
fig
9393
```
94+
### Share bins between histograms
9495

96+
In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/r/reference/#histogram-bingroup) attribute.
97+
```{r}
98+
library(plotly)
99+
100+
fig <- plot_ly(
101+
type='histogram',
102+
x=~rnorm(100, 5),
103+
bingroup=1)
104+
105+
fig <- fig %>% add_trace(
106+
type='histogram',
107+
x=~rnorm(20, 5),
108+
bingroup=1)
109+
110+
fig <- fig %>% layout(
111+
barmode="overlay",
112+
bargap=0.1)
113+
114+
fig
115+
```
116+
Note that traces on the same subplot, and with the same `barmode` ("stack", "relative", "group") are forced into the same `bingroup`, however traces with `barmode = "overlay"` and on different axes (of the same axis type) can have compatible bin settings. Histogram and [histogram2d](https://plot.ly/r/2D-Histogram/) trace can share the same `bingroup`.
117+
118+
```{r}
119+
library(plotly)
120+
121+
fig <- plot_ly(
122+
type='histogram',
123+
x=~rnorm(100, 5))
124+
125+
fig <- fig %>% add_trace(
126+
type='histogram',
127+
x=~rnorm(20, 5))
128+
129+
fig <- fig %>% layout(
130+
barmode="stack",
131+
bargap=0.1)
132+
133+
fig
134+
```
95135
### Reference
96136

97137
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)
0