# Get this figure: fig <- get_figure("messier51", 7) # Get this figure's data: data <- get_figure("messier51", 7)$data # Add data to this figure: p <- add_trace(p, x=c(4, 5), y=c(4, 5), kwargs=list(filename="2014.2015 season", fileopt="extend")) # Get y data of first trace: y1 <- get_figure("messier51", 7)$data[[1]]$y # Get figure documentation: https://plotly.com/r/get-requests/ # Add data documentation: https://plotly.com/r/file-options/ # You can reproduce this figure in R with the following code! # Learn about API authentication here: https://plotly.com/r/getting-started # Find your api_key here: https://plotly.com/settings/api library(plotly) trace1 <- list( uid = "c0916a", line = list( color = "rgb(0, 67, 88)", width = 1 ), mode = "lines+markers", name = "arrow", type = "scatter", x = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"), y = c("1.0", "0.8", "0.9", "1.0", "1.1", "0.9", "0.9", "1.4", "1.1", "1.1", "1.1", "1.2", "1.1", "1.2", "1.1", "0.9", "1.0", "0.8", "0.9", "1."), marker = list( color = "rgb(0, 67, 88)", symbol = "hexagon-open" ), error_x = list(copy_ystyle = TRUE), error_y = list( color = "rgb(0, 67, 88)", width = 1, thickness = 1 ) ) trace2 <- list( uid = "716396", line = list( color = "rgb(31, 138, 112)", width = 1 ), mode = "lines+markers", name = "supernatural", type = "scatter", x = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"), y = c("1.1", "1.0", "0.9", "0.8", "0.9", "1.0", "0.9", "0.9", "1.0", "1.0", "0.7", "0.8", "0.8", "0.8", "0.6", "0.7", "0.6", "0.6", "0.7", "0.7"), marker = list( color = "rgb(31, 138, 112)", symbol = "hexagon-open" ), error_x = list(copy_ystyle = TRUE), error_y = list( color = "rgb(31, 138, 112)", width = 1, thickness = 1 ) ) trace3 <- list( uid = "321b44", line = list( color = "rgb(190, 219, 57)", width = 1 ), mode = "lines+markers", name = "the flash", type = "scatter", x = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"), y = c("1.9", "1.7", "1.5", "1.4", "1.4", "1.4", "1.4", "1.6", "1.5", "1.4", "1.3", "1.3", "1.5", "1.5", "1.3", "1.2", "1.3", "1.4", "1.3", "1.5"), marker = list( color = "rgb(190, 219, 57)", symbol = "hexagon-open" ), error_x = list(copy_ystyle = TRUE), error_y = list( color = "rgb(190, 219, 57)", width = 1, thickness = 1 ) ) data <- list(trace1, trace2, trace3) layout <- list( title = "2014/2015 season", width = 730, xaxis = list( type = "linear", range = c(-0.2308970099667773, 21.230897009966778), title = "episode number", autorange = TRUE ), yaxis = list( type = "linear", range = c(0.5045103092783505, 1.9954896907216493), title = "nielsen 18-49 ", autorange = TRUE ), height = 447, autosize = TRUE, showlegend = TRUE ) p <- plot_ly() p <- add_trace(p, uid=trace1$uid, line=trace1$line, mode=trace1$mode, name=trace1$name, type=trace1$type, x=trace1$x, y=trace1$y, marker=trace1$marker, error_x=trace1$error_x, error_y=trace1$error_y) p <- add_trace(p, uid=trace2$uid, line=trace2$line, mode=trace2$mode, name=trace2$name, type=trace2$type, x=trace2$x, y=trace2$y, marker=trace2$marker, error_x=trace2$error_x, error_y=trace2$error_y) p <- add_trace(p, uid=trace3$uid, line=trace3$line, mode=trace3$mode, name=trace3$name, type=trace3$type, x=trace3$x, y=trace3$y, marker=trace3$marker, error_x=trace3$error_x, error_y=trace3$error_y) p <- layout(p, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis, height=layout$height, autosize=layout$autosize, showlegend=layout$showlegend)