0% found this document useful (0 votes)
1K views2 pages

Plotly Cheatsheet

The document shows examples of using the plot_ly function in R to create different types of plots, including scatter plots, line plots, histograms, box plots, 3D scatter plots, choropleth maps, and 2D histograms. It demonstrates how to customize aspects of the plots like colors, markers, lines, layout, and annotations. Plotly is a library for creating interactive web-based plots in R.

Uploaded by

Raju Rimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views2 pages

Plotly Cheatsheet

The document shows examples of using the plot_ly function in R to create different types of plots, including scatter plots, line plots, histograms, box plots, 3D scatter plots, choropleth maps, and 2D histograms. It demonstrates how to customize aspects of the plots like colors, markers, lines, layout, and annotations. Plotly is a library for creating interactive web-based plots in R.

Uploaded by

Raju Rimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

plot_ly ( plot_ly ( set.seed( 123 ) set.

seed( 123 )
x = c( 1, 2, 3 ), x = c( 1, 2, 3 ), x = 1 : 100 x = 1 : 100
y = c( 5, 6, 7), y = c( 5, 6, 7 ), y1 = 2*x + rnorm ( 100 ) y1 = 2*x + rnorm( 100 )
type = scatter , type = scatter , y2 = -2*x + rnorm ( 100 ) y2 = -2*x + rnorm( 100 )
mode = lines ) mode = markers ,
size = c( 1, 5, 10 ), plot_ly ( axis_template <- list(
marker = list( x=x, showgrid = F ,
color = c( red, blue , y = y1 , zeroline = F ,
green ))) type = scatter ) %>% nticks = 20 ,
showline = T ,
add_trace( title = AXIS ,
x=x, mirror = all )
y = y2 ) %>%
plot.ly/r/getting-started plot_ly ( plot_ly (
x = c( 1, 2, 3 ), x=x,
layout(
y = c( 5, 6, 7 ), y = y1 ,
legend =
type = scatter , type = scatter ) %>%
list( x = 0.5 ,
mode = markers ) y=1,
bgcolor = #F3F3F3 )) layout(
xaxis = axis_template ,
yaxis = axis_template )

library( plotly )
p <- plot_ly (
x = rnorm( 1000 ),
y = rnorm( 1000 ),
mode = markers )
plot_ly ( plot_ly (
x = c( 1, 2, 3), x = c( 1, 2, 3 ),
y = c( 5, 6, 7), y = c( 5, 6, 7 ),
type = bar , type = scatter ,
mode = markers ) mode = lines ,
ll = tozeroy )
plot_ly ( plot_ly ( )
x <- rchisq ( 100, 5, 0 )
type = scattergeo , # Using a dataframe: data data.frame
plot_ly (
lon = c( -73.5, 151.2 ) , plot_ly ( add _trace list ( )
x=x,
lat = c( 45.5, -33.8 ) , type = surface , x, y, z, c ( )
type = histogram )
marker = list ( z = ~volcano ) color, text, size c ( )
color = c( red , blue ) , colorscale string or c ( )
size = c( 30, 50 ) , marker list ( )
mode = markers )) color string
symbol list ( )
line list ( )
color string
width 123

plot_ly ( plot_ly ( plot_ly ( layout ( )


y = rnorm( 50 ) , type = choropleth , type = scatter3d , title string
type = box ) %>% locations = c( AZ, CA, VT ) , x = c( 9, 8, 5, 1 ) , xaxis, yaxis list ( )
locationmode = USA-states , y = c( 1, 2, 4, 8 ) , scenelist ( )
add_trace( y = rnorm( 50, 1 )) colorscale = Viridis , z = c( 11, 8, 15, 3 ) , xaxis, yaxis, zaxis list ( )
z = c( 10, 20, 40 )) %>% mode = lines ) geo list ( )
layout ( geo = list ( scope = usa )) legend list ( )
annotations list ( )

c ( ) = array
list ( ) = list
string = string
123 = number

plot_ly ( plot_ly ( plot_ly (


x = rnorm( 1000, sd = 10 ) , type = scattergeo , type = scatter3d ,
y = rnorm( 1000, sd = 5 ) , lon = c( 42, 39 ) , x = c( 9, 8, 5, 1 ) ,
type = histogram2d ) lat = c( 12, 22 ) , y = c( 1, 2, 4, 8 ) ,
text = c( Rome , Greece ) , z = c( 11, 8, 15, 3 ) ,
mode = markers ) mode = markers )

You might also like