Skip to content

Commit 383873c

Browse files
committed
add R colorway example
1 parent 1e62a00 commit 383873c

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Colorway in R | Examples | Plotly
3+
name: Colorway
4+
permalink: r/colorway/
5+
description: How to set default trace colors using colorway in R with Plotly.
6+
layout: base
7+
language: r
8+
page_type: example_index
9+
has_thumbnail: true
10+
display_as: style_opt
11+
order: 5
12+
output:
13+
html_document:
14+
keep_md: true
15+
---
16+
17+
```{r, echo = FALSE, message=FALSE}
18+
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
19+
Sys.setenv("plotly_username"="RPlotBot")
20+
Sys.setenv("plotly_api_key"="q0lz6r5efr")
21+
```
22+
23+
### New to Plotly?
24+
25+
Plotly's R library is free and open source!<br>
26+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
27+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
28+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
29+
30+
### Version Check
31+
32+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
33+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
34+
35+
```{r}
36+
library(plotly)
37+
packageVersion('plotly')
38+
```
39+
40+
### Set Default Trace Colors with colorway
41+
42+
```{r, results = 'hide'}
43+
library(plotly)
44+
45+
x = seq(-1, 3, length=50)
46+
ones = rep(1, 50)
47+
a_list = seq(1, 3, length=7)
48+
b_list = seq(2, 14, length=7)
49+
df = data.frame(cbind(x, (outer((x*x), a_list) + outer(ones, b_list))))
50+
51+
p <- plot_ly(df, x = ~x, y = ~V2, type = 'scatter', mode = 'lines') %>%
52+
add_trace(y = ~V3) %>%
53+
add_trace(y = ~V4) %>%
54+
add_trace(y = ~V5) %>%
55+
add_trace(y = ~V6) %>%
56+
add_trace(y = ~V7) %>%
57+
add_trace(y = ~V8) %>%
58+
layout(colorway = c('#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844'))
59+
60+
61+
# Create a shareable link to your chart
62+
# Set up API credentials: https://plot.ly/r/getting-started
63+
chart_link = api_create(p, filename="colorway-example")
64+
chart_link
65+
```
66+
67+
```{r, echo=FALSE}
68+
chart_link
69+
```
70+
71+
#Reference
72+
73+
See [https://plot.ly/r/reference](https://plot.ly/r/reference) for more information and chart attribute options!

_posts/r/style/2018-10-03-colorway.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Colorway in R | Examples | Plotly
3+
name: Colorway
4+
permalink: r/colorway/
5+
description: How to set default trace colors using colorway in R with Plotly.
6+
layout: base
7+
language: r
8+
page_type: example_index
9+
has_thumbnail: true
10+
display_as: style_opt
11+
order: 5
12+
output:
13+
html_document:
14+
keep_md: true
15+
---
16+
17+
18+
19+
### New to Plotly?
20+
21+
Plotly's R library is free and open source!<br>
22+
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
23+
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
24+
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
25+
26+
### Version Check
27+
28+
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
29+
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
30+
31+
32+
```r
33+
library(plotly)
34+
packageVersion('plotly')
35+
```
36+
37+
```
38+
## [1] '4.8.0'
39+
```
40+
41+
### Set Default Trace Colors with colorway
42+
43+
44+
```r
45+
library(plotly)
46+
47+
x = seq(-1, 3, length=50)
48+
ones = rep(1, 50)
49+
a_list = seq(1, 3, length=7)
50+
b_list = seq(2, 14, length=7)
51+
df = data.frame(cbind(x, (outer((x*x), a_list) + outer(ones, b_list))))
52+
53+
p <- plot_ly(df, x = ~x, y = ~V2, type = 'scatter', mode = 'lines') %>%
54+
add_trace(y = ~V3) %>%
55+
add_trace(y = ~V4) %>%
56+
add_trace(y = ~V5) %>%
57+
add_trace(y = ~V6) %>%
58+
add_trace(y = ~V7) %>%
59+
add_trace(y = ~V8) %>%
60+
layout(colorway = c('#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844'))
61+
62+
63+
# Create a shareable link to your chart
64+
# Set up API credentials: https://plot.ly/r/getting-started
65+
chart_link = api_create(p, filename="colorway-example")
66+
chart_link
67+
```
68+
69+
<iframe src="https://plot.ly/~RPlotBot/5487.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
70+
71+
#Reference
72+
73+
See [https://plot.ly/r/reference](https://plot.ly/r/reference) for more information and chart attribute options!

0 commit comments

Comments
 (0)