Skip to content

Commit 3a8b850

Browse files
committed
ohlc shapes and annotations
1 parent e85ecdd commit 3a8b850

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

_posts/r/2017-02-03-ohlc-charts.Rmd

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,56 @@ chart_link
6464
chart_link
6565
```
6666

67+
### Customise the Figure with Shapes and Annotations
68+
69+
```{r, results = 'hide'}
70+
library(plotly)
71+
library(quantmod)
72+
73+
getSymbols("AAPL",src='yahoo')
74+
75+
df <- data.frame(Date=index(AAPL),coredata(AAPL))
76+
77+
# annotation
78+
a <- list(text = "Stock Split",
79+
x = '2014-06-06',
80+
y = 1.02,
81+
xref = 'x',
82+
yref = 'paper',
83+
xanchor = 'left',
84+
showarrow = FALSE
85+
)
86+
87+
# use shapes to create a line
88+
l <- list(type = line,
89+
x0 = '2014-06-06',
90+
x1 = '2014-06-06',
91+
y0 = 0,
92+
y1 = 1,
93+
xref = 'x',
94+
yref = 'paper',
95+
line = list(color = 'black',
96+
width = 0.5)
97+
)
98+
99+
p <- df %>%
100+
plot_ly(x = ~Date, type="ohlc",
101+
open = ~AAPL.Open, close = ~AAPL.Close,
102+
high = ~AAPL.High, low = ~AAPL.Low) %>%
103+
layout(title = "Apple Stock",
104+
annotations = a,
105+
shapes = l)
106+
107+
# Create a shareable link to your chart
108+
# Set up API credentials: https://plot.ly/r/getting-started
109+
chart_link = plotly_POST(p, filename="finance/ohlc-shapes-annot")
110+
chart_link
111+
```
112+
113+
```{r, echo=FALSE}
114+
chart_link
115+
```
116+
67117
#Reference
68118

69119
See [https://plot.ly/r/reference/#ohlc](https://plot.ly/r/reference/#ohlc) for more information and chart attribute options!

_posts/r/2017-02-03-ohlc-charts.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,55 @@ chart_link
6464

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

67+
### Customise the Figure with Shapes and Annotations
68+
69+
70+
```r
71+
library(plotly)
72+
library(quantmod)
73+
74+
getSymbols("AAPL",src='yahoo')
75+
76+
df <- data.frame(Date=index(AAPL),coredata(AAPL))
77+
78+
# annotation
79+
a <- list(text = "Stock Split",
80+
x = '2014-06-06',
81+
y = 1.02,
82+
xref = 'x',
83+
yref = 'paper',
84+
xanchor = 'left',
85+
showarrow = FALSE
86+
)
87+
88+
# use shapes to create a line
89+
l <- list(type = line,
90+
x0 = '2014-06-06',
91+
x1 = '2014-06-06',
92+
y0 = 0,
93+
y1 = 1,
94+
xref = 'x',
95+
yref = 'paper',
96+
line = list(color = 'black',
97+
width = 0.5)
98+
)
99+
100+
p <- df %>%
101+
plot_ly(x = ~Date, type="ohlc",
102+
open = ~AAPL.Open, close = ~AAPL.Close,
103+
high = ~AAPL.High, low = ~AAPL.Low) %>%
104+
layout(title = "Apple Stock",
105+
annotations = a,
106+
shapes = l)
107+
108+
# Create a shareable link to your chart
109+
# Set up API credentials: https://plot.ly/r/getting-started
110+
chart_link = plotly_POST(p, filename="finance/ohlc-shapes-annot")
111+
chart_link
112+
```
113+
114+
<iframe src="https://plot.ly/~RPlotBot/4301.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
115+
67116
#Reference
68117

69118
See [https://plot.ly/r/reference/#ohlc](https://plot.ly/r/reference/#ohlc) for more information and chart attribute options!

0 commit comments

Comments
 (0)