Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
New to Plotly
Shapes in R
Version Check How to use shapes in R. Two examples on highlighting regions by
adding shapes to your R charts.
Lines
Circles
Reference
Back To R
New to Plotly?
Version Check
https://plot.ly/r/shapes/ 1/11
11/1/2017 Shapes in R | Examples | Plotly
Copy to clipboard!
library(plotly)
packageVersion('plotly')
Copy to clipboard!
## [1] '4.7.0.9000'
Lines
Copy to clipboard!
s <- seq.int(0, 15)
p <- plot_ly(x = ~s, y = ~sin(s), mode = "lines")
https://plot.ly/r/shapes/ 3/11
11/1/2017 Shapes in R | Examples | Plotly
4 4 Plot twist!
There's nothing here...
Rectangles
https://plot.ly/r/shapes/ 4/11
11/1/2017 Shapes in R | Examples | Plotly
Copy to clipboard!
library(plotly)
p <- plot_ly(economics, x = ~date, y = ~uempmed, name = "unemployment")
https://plot.ly/r/shapes/ 5/11
11/1/2017 Shapes in R | Examples | Plotly
4 4 Plot twist!
There's nothing here...
Circles
https://plot.ly/r/shapes/ 6/11
11/1/2017 Shapes in R | Examples | Plotly
Copy to clipboard!
library(plotly)
d <- diamonds[sample(nrow(diamonds), 1000), ]
d <- plot_ly(d, x = ~carat, y = ~price, text = ~paste("Clarity: ", clarity),
mode = "markers", color = ~carat, size = ~carat, opacity = ~carat)
d <- layout(d, title = 'Highlighting Regions with Circles',
shapes = list(
list(type = 'circle',
xref = 'x', x0 = .2, x1 = .7,
yref = 'y', y0 = 20, y1 = 3000,
fillcolor = 'rgb(50, 20, 90)', line = list(color = 'rgb(50, 20,
90)'),
opacity = 0.2),
list(type = 'circle',
xref = 'x', x0 = .75, x1 = 1.5,
yref = 'y', y0 = 2500, y1 = 7500,
fillcolor = 'rgb(30, 100, 120)', line = list(color = 'rgb(30, 100, 12
0)'),
opacity = 0.2),
list(type = 'circle',
xref = 'x', x0 = 1.6, x1 = 2.5,
yref = 'y', y0 = 12500, y1 = 18500,
fillcolor = 'rgb(90, 200, 75)', line = list(color = 'rgb(90, 200, 7
5)'),
opacity = 0.2)))
https://plot.ly/r/shapes/ 7/11
11/1/2017 Shapes in R | Examples | Plotly
Copy to clipboard!
Copy to clipboard!
chart_link
https://plot.ly/r/shapes/ 8/11
11/1/2017 Shapes in R | Examples | Plotly
4 4 Plot twist!
There's nothing here...
Reference
Check out our reference page for more information on using shapes!
https://plot.ly/r/shapes/ 9/11
11/1/2017 Shapes in R | Examples | Plotly
Contact Us
Solutions Connect
Copyright © 2015 Plotly. All rights reserved. Terms of Service Privacy Policy
https://plot.ly/r/shapes/ 11/11