# Get this figure: fig <- get_figure("mwarzecha", 277) # Get this figure's data: data <- get_figure("mwarzecha", 277)$data # Add data to this figure: p <- add_trace(p, x=c(4, 5), y=c(4, 5), kwargs=list(filename="% Of candidates that are women, by party", fileopt="extend")) # Get y data of first trace: y1 <- get_figure("mwarzecha", 277)$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 = "dde989", name = "NDP", type = "bar", x = c("38th election - 2004", "39th election - 2006", "40th election - 2008", "41st election - 2011", "42nd election - As of Sept. 21"), y = c("31.17%", "35.06%", "33.77%", "40.26%", "43.49%"), marker = list(color = "rgb(255, 127, 14)") ) trace2 <- list( uid = "8a1a2f", name = "Liberal", type = "bar", x = c("38th election - 2004", "39th election - 2006", "40th election - 2008", "41st election - 2011", "42nd election - As of Sept. 21"), y = c("24.35%", "25.65%", "36.81%", "29.22%", "31.07%"), marker = list(color = "rgb(255, 0, 0)") ) trace3 <- list( uid = "6f0e06", name = "Bloc Québécois", type = "bar", x = c("38th election - 2004", "39th election - 2006", "40th election - 2008", "41st election - 2011", "42nd election - As of Sept. 21"), y = c("24.00%", "30.67%", "26.67%", "32.00%", "28.57%"), marker = list(color = "rgb(74, 134, 232)") ) trace4 <- list( uid = "0bd721", name = "Conservatives", type = "bar", x = c("38th election - 2004", "39th election - 2006", "40th election - 2008", "41st election - 2011", "42nd election - As of Sept. 21"), y = c("11.69%", "12.34%", "20.52%", "22.15%", "19.58%"), marker = list(color = "rgb(0, 0, 255)") ) data <- list(trace1, trace2, trace3, trace4) layout <- list( title = "% Of candidates that are women, by party", width = 1143, xaxis = list( type = "category", range = c(-0.5, 4.5), title = "Click to enter X axis title", autorange = TRUE ), yaxis = list( range = c(0, 45.77894736842106), title = "%", autorange = TRUE ), height = 607, autosize = TRUE ) p <- plot_ly() p <- add_trace(p, uid=trace1$uid, name=trace1$name, type=trace1$type, x=trace1$x, y=trace1$y, marker=trace1$marker) p <- add_trace(p, uid=trace2$uid, name=trace2$name, type=trace2$type, x=trace2$x, y=trace2$y, marker=trace2$marker) p <- add_trace(p, uid=trace3$uid, name=trace3$name, type=trace3$type, x=trace3$x, y=trace3$y, marker=trace3$marker) p <- add_trace(p, uid=trace4$uid, name=trace4$name, type=trace4$type, x=trace4$x, y=trace4$y, marker=trace4$marker) p <- layout(p, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis, height=layout$height, autosize=layout$autosize)