Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ad7128

Browse files
committed
added tickformatstops working example by specitying type=date
1 parent 31143ac commit 5ad7128

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

_posts/r/layout/tick-format/2019-03-08-tick-formatting.Rmd

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,108 @@ chart_link
111111
```
112112

113113

114+
```{r, echo=FALSE}
115+
chart_link
116+
```
117+
118+
### Using Tickformat (Date)
119+
120+
```{r, results = "hide"}
121+
library(plotly)
122+
123+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
124+
125+
p <- plot_ly(
126+
type = "scatter",
127+
x = df$Date,
128+
y = df$AAPL.High,
129+
name = 'AAPL High',
130+
mode = "lines",
131+
line = list(
132+
color = '#17BECF'
133+
)) %>%
134+
add_trace(
135+
type = "scatter",
136+
x = df$Date,
137+
y = df$AAPL.Low,
138+
name = 'AAPL Low',
139+
mode = "lines",
140+
line = list(
141+
color = '#7F7F7F'
142+
)) %>%
143+
layout(
144+
title = "Time Series with Custom Date-Time Format",
145+
xaxis = list(
146+
type = 'date',
147+
tickformat = "%d %B (%a)<br>%Y"
148+
))
149+
150+
# Create a shareable link to your chart
151+
# Set up API credentials: https://plot.ly/r/getting-started
152+
chart_link = api_create(p, filename="using-tickformat-attribute-date")
153+
chart_link
154+
```
155+
156+
```{r, echo=FALSE}
157+
chart_link
158+
```
159+
160+
### Tickformatstops to customize for different zoom levels
161+
162+
```{r, results = "hide"}
163+
library(plotly)
164+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
165+
p <- plot_ly(
166+
type = "scatter",
167+
x = df$Date,
168+
y = df$mavg,
169+
mode = "lines") %>%
170+
layout(
171+
xaxis = list(
172+
type='date',
173+
tickformatstops = list(
174+
list(
175+
dtickrange = list(NULL, 1000),
176+
value = "%H:%M:%S.%L ms"
177+
),
178+
list(
179+
dtickrange = list(1000, 60000),
180+
value = "%H:%M:%S s"
181+
),
182+
list(
183+
dtickrange = list(60000, 3600000),
184+
value = "%H:%M m"
185+
),
186+
list(
187+
dtickrange = list(3600000, 86400000),
188+
value = "%H:%M h"
189+
),
190+
list(
191+
dtickrange = list(86400000, 604800000),
192+
value = "%e. %b d"
193+
),
194+
list(
195+
dtickrange = list(604800000, "M1"),
196+
value = "%e. %b w"
197+
),
198+
list(
199+
dtickrange = list("M1", "M12"),
200+
value = "%b '%y M"
201+
),
202+
list(
203+
dtickrange = list("M12", NULL),
204+
value = "%Y Y"
205+
)
206+
)
207+
)
208+
)
209+
210+
# Create a shareable link to your chart
211+
# Set up API credentials: https://plot.ly/r/getting-started
212+
chart_link = api_create(p, filename="using-tickformatstops")
213+
chart_link
214+
```
215+
114216
```{r, echo=FALSE}
115217
chart_link
116218
```

_posts/r/layout/tick-format/2019-03-08-tick-formatting.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,106 @@ chart_link
109109

110110
<iframe src="https://plot.ly/~RPlotBot/5619.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
111111

112+
### Using Tickformat (Date)
113+
114+
115+
```r
116+
library(plotly)
117+
118+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
119+
120+
p <- plot_ly(
121+
type = "scatter",
122+
x = df$Date,
123+
y = df$AAPL.High,
124+
name = 'AAPL High',
125+
mode = "lines",
126+
line = list(
127+
color = '#17BECF'
128+
)) %>%
129+
add_trace(
130+
type = "scatter",
131+
x = df$Date,
132+
y = df$AAPL.Low,
133+
name = 'AAPL Low',
134+
mode = "lines",
135+
line = list(
136+
color = '#7F7F7F'
137+
)) %>%
138+
layout(
139+
title = "Time Series with Custom Date-Time Format",
140+
xaxis = list(
141+
type = 'date',
142+
tickformat = "%d %B (%a)<br>%Y"
143+
))
144+
145+
# Create a shareable link to your chart
146+
# Set up API credentials: https://plot.ly/r/getting-started
147+
chart_link = api_create(p, filename="using-tickformat-attribute-date")
148+
chart_link
149+
```
150+
151+
<iframe src="https://plot.ly/~RPlotBot/5621.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
152+
153+
### Tickformatstops to customize for different zoom levels
154+
155+
156+
```r
157+
library(plotly)
158+
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
159+
p <- plot_ly(
160+
type = "scatter",
161+
x = df$Date,
162+
y = df$mavg,
163+
mode = "lines") %>%
164+
layout(
165+
xaxis = list(
166+
type='date',
167+
tickformatstops = list(
168+
list(
169+
dtickrange = list(NULL, 1000),
170+
value = "%H:%M:%S.%L ms"
171+
),
172+
list(
173+
dtickrange = list(1000, 60000),
174+
value = "%H:%M:%S s"
175+
),
176+
list(
177+
dtickrange = list(60000, 3600000),
178+
value = "%H:%M m"
179+
),
180+
list(
181+
dtickrange = list(3600000, 86400000),
182+
value = "%H:%M h"
183+
),
184+
list(
185+
dtickrange = list(86400000, 604800000),
186+
value = "%e. %b d"
187+
),
188+
list(
189+
dtickrange = list(604800000, "M1"),
190+
value = "%e. %b w"
191+
),
192+
list(
193+
dtickrange = list("M1", "M12"),
194+
value = "%b '%y M"
195+
),
196+
list(
197+
dtickrange = list("M12", NULL),
198+
value = "%Y Y"
199+
)
200+
)
201+
)
202+
)
203+
204+
# Create a shareable link to your chart
205+
# Set up API credentials: https://plot.ly/r/getting-started
206+
chart_link = api_create(p, filename="using-tickformatstops")
207+
chart_link
208+
```
209+
210+
<iframe src="https://plot.ly/~RPlotBot/5627.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
211+
112212
### Using Exponentformat
113213

114214

0 commit comments

Comments
 (0)