8000 Merge pull request #51 from plotly/plotlyjs1-54-docs-update · plotly/plotly.r-docs@411c402 · GitHub
[go: up one dir, main page]

Skip to content

Commit 411c402

Browse files
Merge pull request #51 from plotly/plotlyjs1-54-docs-update
Plotlyjs1 54 docs update
2 parents e70b753 + ec5a8ce commit 411c402

File tree

5 files changed

+168
-1
lines changed

5 files changed

+168
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
name: install application-level dependencies
2626
command: |
2727
sudo apt-get install -y pandoc libudunits2-dev libgdal-dev libxt-dev libglu1-mesa-dev libfftw3-dev
28-
sudo R -e 'install.packages(c("plotly", "curl", "devtools", "mvtnorm")); devtools::install_github("hypertidy/anglr"); devtools::install_github("johannesbjork/LaCroixColoR"); install.packages("BiocManager"); BiocManager::install("EBImage"); devtools::install_deps(dependencies = TRUE) '
28+
sudo R -e 'install.packages(c("curl", "devtools", "mvtnorm")); devtools::install_github("hypertidy/anglr"); devtools::install_github("ropensci/plotly"); devtools::install_github("johannesbjork/LaCroixColoR"); install.packages("BiocManager"); BiocManager::install("EBImage"); devtools::install_deps(dependencies = TRUE) '
2929
- save_cache:
3030
key: cache4
3131
paths:

r/2015-07-30-time-series.Rmd

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,55 @@ fig <- plot_ly(x = ~x, y = ~y, mode = 'lines', text = paste(tm, "days from today
2929
fig
3030
```
3131

32+
### Hiding Weekends and Holidays
33+
The `rangebreaks` attribute available on x- and y-axes of type date can be used to hide certain time-periods. In the example below, we show two plots: one in default mode to show gaps in the data, and one where we hide weekends and holidays to show an uninterrupted trading history. Note the smaller gaps between the grid lines for December 21 and January 4, where holidays were removed. Check out the reference for more options: https://plotly.com/r/reference/#layout-xaxis-rangebreaks
34+
35+
36+
```{r}
37+
library(plotly)
38+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
39+
fig <- plot_ly(
40+
type = "scatter",
41+
x = as.Date(df$Date, format= "%Y-%m-%d"),
42+
y = df$AAPL.High,
43+
name = 'AAPL High',
44+
mode = "markers",
45+
)
46+
fig <- fig %>%
47+
layout(
48+
title = "Time Series with Custom Date-Time Format",
49+
xaxis = list(
50+
type = "date",
51+
range=c('2015-12-01', '2016-01-15')
52+
)
53+
)
54+
fig
55+
```
56+
57+
```{r}
58+
library(plotly)
59+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
60+
fig <- plot_ly(
61+
type = "scatter",
62+
x = as.Date(df$Date, format= "%Y-%m-%d"),
63+
y = df$AAPL.High,
64+
name = 'AAPL High',
65+
mode = "markers",
66+
)
67+
fig <- fig %>%
68+
layout(
69+
title = "Time Series with Custom Date-Time Format",
70+
xaxis = list(
71+
type = "date",
72+
range=c('2015-12-01', '2016-01-15'),
73+
rangebreaks = list(
74+
list(bounds=c("sat", "mon")),
75+
list(values=c("2015-12-25", "2016-01-01"))
76+
)
77+
)
78+
)
79+
fig
80+
```
3281
### POSIXlt date time class with timezone
3382

3483
```{r}

r/2015-11-19-shapes.Rmd

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,62 @@ fig <- layout(fig, title = 'Highlighting Regions with Circles',
9696
fig
9797
```
9898

99+
### Drawing Shapes on Cartesian Plots
100+
101+
You can create layout shapes programatically, but you can also draw shapes manually by setting the `dragmode` to one of the shape-drawing modes: `drawline`,`drawopenpath`, `drawclosedpath`, `drawcircle`, or `drawrect`. If you need to switch between different shape-drawing or other dragmodes (panning, selecting, etc.), modebar buttons can be added in the `config` of your figure to select the dragmode.
102+
103+
If you switch to a different dragmode such as pan or zoom, you will need to select the drawing tool in the modebar to go back to shape drawing.
104+
105+
This shape-drawing feature is particularly interesting for annotating graphs, in particular [image traces](https://plotly.com/r/displaying-images/#drawing-shapes-on-images).
106+
107+
Once you have drawn shapes, you can select and modify an existing shape by clicking on its boundary (note the arrow pointer). Its fillcolor turns to pink to highlight the activated shape and then you can
108+
109+
- drag and resize it for lines, rectangles and circles/ellipses
110+
- drag and move individual vertices for closed paths
111+
- move individual vertices for open paths.
112+
113+
An activated shape is deleted by cliking on the `eraseshape` button.
114+
115+
Drawing or modifying a shape triggers a `relayout` event, which [can be captured by a callback inside a Dash For R application](https://dash.plotly.com/interactive-graphing).
116+
117+
```{r}
118+
library(plotly)
119+
120+
df <- diamonds[sample(nrow(diamonds), 1000), ]
121+
122+
fig <- plot_ly(df, x = ~carat, y = ~price, text = ~paste("Clarity: ", clarity),
123+
mode = "markers", color = ~carat, size = ~carat)
124+
125+
fig <- layout(fig, dragmode="drawrect", xaxis = list(title = 'Click and drag inside the figure to draw a rectangle or select another shape in the modebar'))
126+
127+
fig <- fig %>%
128+
config(modeBarButtonsToAdd = list("drawine", "drawopenpath", "drawclosedpath", "drawcircle", "drawrect", "eraseshape" ) )
129+
130+
fig
131+
132+
```
133+
134+
### Style of user-drawn shapes
135+
136+
The layout `newshape` attribute controls the visual appearance of new shapes drawn by the user. `newshape` attributes have the same names as layout shapes.
137+
138+
Note on shape opacity: having a new shape's opacity > 0.5 makes it possible to activate a shape by clicking inside the shape (for opacity <= 0.5 you have to click on the border of the shape), but you cannot start a new shape within an existing shape (which is possible for an opacity <= 0.5).
139+
140+
```{r}
141+
library(plotly)
142+
143+
df <- diamonds[sample(nrow(diamonds), 1000), ]
144+
145+
fig <- plot_ly(df, x = ~carat, y = ~price, text = ~paste("Clarity: ", clarity),
146+
mode = "markers", color = ~carat, size = ~carat)
147+
148+
fig <- layout(fig, dragmode="drawrect", newshape=list(fillcolor="yellow", opacity=0.5), xaxis = list(title = 'Click and drag inside the figure to draw a rectangle or select another shape in the modebar'))
149+
150+
fig <- fig %>%
151+
config(modeBarButtonsToAdd = list("drawine", "drawopenpath", "drawclosedpath", "drawcircle", "drawrect", "eraseshape" ) )
152+
153+
fig
154+
155+
```
99156
### Reference
100157
Check out our <b>[reference page](https://plotly.com/r/reference/#layout-shapes)</b> for more information on using shapes!

r/2018-01-29-hover-text-and-formatting.Rmd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ fig <- fig %>%
3535
fig
3636
```
3737

38+
#### Unified hovermode
39+
40+
If you set the `hovermode` attribute of your figure's layout to `x unified` or `y unified`), a single hover label will appear, describing one point per trace, for points at the same x (or y) value as the cursor.
41+
42+
If multiple points in a given trace exist at the same coordinate, only one will get an entry in the hover label. In the line plot below we have forced markers to appear, to make it clearer what can be hovered over:
43+
44+
```{r}
45+
library(plotly)
46+
47+
trace_0 <- rnorm(100, mean = 5)
48+
trace_1 <- rnorm(100, mean = 0)
49+
trace_2 <- rnorm(100, mean = -5)
50+
x <- c(1:100)
51+
52+
data <- data.frame(x, trace_0, trace_1, trace_2)
53+
54+
fig <- plot_ly(data, x = ~x, y = ~trace_0, name = 'trace 0', type = 'scatter', mode = 'lines')
55+
fig <- fig %>% add_trace(y = ~trace_1, name = 'trace 1', mode = 'lines+markers')
56+
fig <- fig %>% add_trace(y = ~trace_2, name = 'trace 2', mode = 'markers')
57+
fig <- fig %>%
58+
layout(hovermode = "x unified")
59+
fig
60+
```
61+
3862
#### Format Hover Text
3963

4064
```{r}

r/2020-02-25-images.Rmd

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,42 @@ fig <- fig %>% layout(margin=list(l=10, r=10, b=0, t=0),
7272
fig
7373
```
7474< 10000 code class="diff-text syntax-highlighted-line">

75+
### Drawing Shapes on Images
76+
77+
You can create layout shapes programatically, but you can also draw shapes manually by setting the `dragmode` to one of the shape-drawing modes: `drawline`,`drawopenpath`, `drawclosedpath`, `drawcircle`, or `drawrect`. If you need to switch between different shape-drawing or other dragmodes (panning, selecting, etc.), modebar buttons can be added in the `config` of your figure to select the dragmode.
78+
79+
If you switch to a different dragmode such as pan or zoom, you will need to select the drawing tool in the modebar to go back to shape drawing.
80+
81+
This shape-drawing feature is particularly interesting for annotating graphs, in particular [image traces](https://plotly.com/r/displaying-images/).
82+
83+
Once you have drawn shapes, you can select and modify an existing shape by clicking on its boundary (note the arrow pointer). Its fillcolor turns to pink to highlight the activated shape and then you can
84+
85+
- drag and resize it for lines, rectangles and circles/ellipses
86+
- drag and move individual vertices for closed paths
87+
- move individual vertices for open paths.
88+
89+
An activated shape is deleted by cliking on the `eraseshape` button.
90+
91+
Drawing or modifying a shape triggers a `relayout` event, which [can be captured by a callback inside a Dash For R application](https://dash.plotly.com/interactive-graphing).
92+
93+
```{r}
94+
library(plotly)
95+
96+
library(plotly)
97+
library(EBImage)
98+
99+
img = readImage('https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Crab_Nebula.jpg/240px-Crab_Nebula.jpg')
100+
101+
fig <- plot_ly(type="image", z=img*255)
102+
103+
fig <- layout(fig, dragmode="drawrect", xaxis = list(title = 'Click and drag inside the figure to draw a rectangle or select another shape in the modebar'))
104+
105+
fig <- fig %>%
106+
config(modeBarButtonsToAdd = list("drawine", "drawopenpath", "drawclosedpath", "drawcircle", "drawrect", "eraseshape" ) )
107+
108+
fig
109+
110+
```
111+
75112
### Reference
76113
See [https://plotly.com/r/reference/#image](https://plotly.com/r/reference/#area) for more information and chart attribute options!

0 commit comments

Comments
 (0)
0