Skip to content

Commit 640c66c

Browse files
author
Joseph Damiba
committed
finalize new docs
1 parent e45bbf2 commit 640c66c

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,23 @@ fig
3030
```
3131

3232
### 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 create a plot of the last ten days, excluding Saturdays, Sundays, yesterday, and the day before yesterday. Check out the reference for more options: https://plotly.com/r/reference/#layout-xaxis-rangebreaks
3334

3435
```{r}
3536
library(plotly)
36-
37-
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
38-
39-
fig <- plot_ly(
40-
type = "scatter",
41-
x = df$Date,
42-
y = df$AAPL.High,
43-
name = 'AAPL High',
44-
mode = "lines",
45-
x_axis= c('2015-12-01', '2016-01-15'),
46-
line = list(
47-
color = '#17BECF'
48-
))
49-
50-
fig <- fig %>%
51-
layout(
52-
title = "Time Series with Custom Date-Time Format",
53-
xaxis = list(rangebreaks = list(list(bounds=c('sat', 'mon')), list(values=c('2015-12-25', '2016-01-15'))))
54-
)
55-
37+
today <- Sys.Date()
38+
yesterday = today - 1
39+
day_before_yesterday = yesterday - 1
40+
tm <- seq(0, 10, by = 1)
41+
x <- today - tm
42+
y <- rnorm(length(x))
43+
fig <- plot_ly(x = ~x, y = ~y, mode = 'markers', text = paste(tm, "days from today"))
44+
fig <- fig %>% layout(
45+
xaxis = list(rangebreaks = list(
46+
list(bounds=c("sat", "sun")),
47+
list(values=c(yesterday,day_before_yesterday))
48+
))
49+
)
5650
fig
5751
```
5852
### POSIXlt date time class with timezone

r/2015-11-19-shapes.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ You can create layout shapes programatically, but you can also draw shapes manua
102102

103103
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.
104104

105-
This shape-drawing feature is particularly interesting for annotating graphs, in particular [image traces](https://plotly.com/r/displaying-images/).
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).
106106

107107
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
108108

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

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)