# Get this figure: fig <- get_figure("MattSundquist", 1339) # Get this figure's data: data <- get_figure("MattSundquist", 1339)$data # Add data to this figure: p <- add_trace(p, x=c(4, 5), y=c(4, 5), kwargs=list(filename="plot from API (242)", fileopt="extend")) # Get y data of first trace: y1 <- get_figure("MattSundquist", 1339)$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 = "5485f4", fill = "none", line = list( dash = "solid", color = "rgb(0, 0, 255)", shape = "spline", width = 2 ), mode = "lines", name = "Chile", text = Null, type = "scatter", x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012), y = c(Null, Null, 600, 640, 660, 650, 740, 760, 770, 800, 860, 1020, 1110, 1320, 1620, 1120, 980, 1070, 1320, 1740, 2240, 2640, 2190, 1780, 1600, 1410, 1410, 1560, 1820, 2090, 2240, 2490, 3020, 3330, 3610, 4320, 4930, 5380, 5250, 4910, 4920, 4760, 4550, 4570, 5230, 6250, 7260, 8630, 10020, 9930, 10720, 12270, 14310), marker = list( line = list( color = "#000", width = 0 ), size = 6, cauto = TRUE, color = "rgb(0, 0, 255)", symbol = "circle", opacity = 0.5, colorscale = list(c(0, "rgb(8, 29, 88)"),list(0.125, "rgb(37, 52, 148)"),list(0.25, "rgb(34, 94, 168)"),list(0.375, "rgb(29, 145, 192)"),list(0.5, "rgb(65, 182, 196)"),list(0.625, "rgb(127, 205, 187)"),list(0.75, "rgb(199, 233, 180)"),list(0.875, "rgb(237, 248, 217)"),list(1, "rgb(255, 255, 217)")) ), error_x = lis), error_y = lis), error_z = lis), opacity = 1, textfont = list( size = 12, color = "#000", family = "'Open sans', verdana, arial, sans-serif" ), fillcolor = "rgba(0, 0, 255, 0.5)", textposition = "middle center" ) trace2 <- list( uid = "cc0f76", fill = "none", line = list( dash = "solid", color = "rgb(255, 0, 0)", shape = "spline", width = 2 ), mode = "lines", name = "Hungary", text = Null, type = "scatter", x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012), y = c(Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, 540, 590, 670, 830, 1000, 1150, 1200, 1330, 1520, 1770, 2070, 2200, 2170, 2010, 1930, 1860, 2040, 2400, 2710, 2770, 2880, 2740, 3140, 3630, 4000, 4220, 4320, 4370, 4380, 4460, 4580, 4720, 5210, 6550, 8540, 10220, 11040, 11510, 12890, 12980, 12930, 12900, 12410), marker = list( line = list( color = "#000", width = 0 ), size = 6, cauto = TRUE, color = "rgb(255, 0, 0)", symbol = "circle", opacity = 1, colorscale = list(c(0, "rgb(8, 29, 88)"),list(0.125, "rgb(37, 52, 148)"),list(0.25, "rgb(34, 94, 168)"),list(0.375, "rgb(29, 145, 192)"),list(0.5, "rgb(65, 182, 196)"),list(0.625, "rgb(127, 205, 187)"),list(0.75, "rgb(199, 233, 180)"),list(0.875, "rgb(237, 248, 217)"),list(1, "rgb(255, 255, 217)")) ), error_x = lis), error_y = lis), error_z = lis), opacity = 0.8, textfont = list( size = 12, color = "#000", family = "'Open sans', verdana, arial, sans-serif" ), fillcolor = "rgba(255, 0, 0, 0.5)", textposition = "middle center" ) trace3 <- list( uid = "fe96aa", line = list( color = "rgb(44, 160, 44)", shape = "spline", width = 2 ), mode = "lines", name = "Uruguay", text = Null, type = "scatter", x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012), y = c(Null, Null, 580, 610, 660, 680, 720, 640, 610, 670, 820, 850, 870, 1060, 1370, 1620, 1490, 1420, 1630, 2150, 2870, 3650, 3290, 2190, 1740, 1510, 1780, 2210, 2600, 2730, 2840, 3180, 3830, 4350, 5040, 5530, 6160, 6970, 7240, 7260, 7050, 6500, 5140, 4240, 4130, 4720, 5380, 6380, 7690, 8520, 10110, 11700, 13580), error_x = lis), error_y = lis), error_z = lis), textfont = lis) ) data <- list(trace1, trace2, trace3) layout <- list( font = list( size = 12, color = "#000", family = "'Open sans', verdana, arial, sans-serif" ), smith = FALSE, title = "", width = 816, xaxis = list( type = "linear", dtick = 1, range = c(1960, 2012), tick0 = 0, ticks = "", title = "year", anchor = "y", domain = c(0, 1), mirror = "all", nticks = 0, ticklen = 5, autotick = TRUE, position = 0, showgrid = TRUE, showline = TRUE, tickfont = list( size = 0, color = "", family = "" ), zeroline = TRUE, autorange = TRUE, gridcolor = "white", gridwidth = 1, linecolor = "white", linewidth = 1, rangemode = "normal", tickangle = "auto", tickcolor = "#000", tickwidth = 1, titlefont = list( size = 0, color = "", family = "" ), overlaying = FALSE, showexponent = "all", zerolinecolor = "white", zerolinewidth = 1, exponentformat = "e", showticklabels = TRUE ), yaxis = list( type = "log", dtick = 0.2, range = c(2.6533245446042573, 4.234708848978488), tick0 = 0, ticks = "", title = "NY.GNP.PCAP.CD", anchor = "x", domain = c(0, 1), mirror = "all", nticks = 0, ticklen = 5, autotick = TRUE, position = 0, showgrid = TRUE, showline = TRUE, tickfont = list( size = 0, color = "", family = "" ), zeroline = TRUE, autorange = TRUE, gridcolor = "white", gridwidth = 1, linecolor = "white", linewidth = 1, rangemode = "normal", tickangle = "auto", tickcolor = "#000", tickwidth = 1, titlefont = list( size = 0, color = "", family = "" ), overlaying = FALSE, showexponent = "all", zerolinecolor = "white", zerolinewidth = 1, exponentformat = "e", showticklabels = TRUE ), bargap = 0.2, boxgap = 0.3, height = 492, legend = list( x = 1.019448946515397, y = 1.0032051282051282, font = list( size = 0, color = "", family = "" ), bgcolor = "#fff", xanchor = "left", yanchor = "auto", traceorder = "normal", bordercolor = "rgb(255, 255, 255)", borderwidth = 1 ), margin = list( b = 80, l = 80, r = 80, t = 100, pad = 0, autoexpand = TRUE ), barmode = "group", boxmode = "overlay", autosize = TRUE, dragmode = "zoom", hovermode = "closest", titlefont = list( size = 0, color = "", family = "" ), separators = ".,", showlegend = TRUE, annotations = list( list( x = 0.9880317848410782, y = 0.02994334820619583, ax = -10, ay = -28.335936546325684, tag = "", font = list( size = 0, color = "", family = "" ), text = "Source: World Bank", xref = "paper", yref = "paper", align = "center", bgcolor = "rgba(0,0,0,0)", opacity = 1, xanchor = "auto", yanchor = "auto", arrowhead = 1, arrowsize = 1, borderpad = 1, showarrow = FALSE, textangle = 0, arrowcolor = "", arrowwidth = 0, bordercolor = "", borderwidth = 1 ) ), bargroupgap = 0, boxgroupgap = 0.3, hidesources = FALSE, plot_bgcolor = "rgb(245,245,247)", paper_bgcolor = "#fff" ) p <- plot_ly() p <- add_trace(p, uid=trace1$uid, fill=trace1$fill, line=trace1$line, mode=trace1$mode, name=trace1$name, text=trace1$text, type=trace1$type, x=trace1$x, y=trace1$y, marker=trace1$marker, error_x=trace1$error_x, error_y=trace1$error_y, error_z=trace1$error_z, opacity=trace1$opacity, textfont=trace1$textfont, fillcolor=trace1$fillcolor, textposition=trace1$textposition) p <- add_trace(p, uid=trace2$uid, fill=trace2$fill, line=trace2$line, mode=trace2$mode, name=trace2$name, text=trace2$text, type=trace2$type, x=trace2$x, y=trace2$y, marker=trace2$marker, error_x=trace2$error_x, error_y=trace2$error_y, error_z=trace2$error_z, opacity=trace2$opacity, textfont=trace2$textfont, fillcolor=trace2$fillcolor, textposition=trace2$textposition) p <- add_trace(p, uid=trace3$uid, line=trace3$line, mode=trace3$mode, name=trace3$name, text=trace3$text, type=trace3$type, x=trace3$x, y=trace3$y, error_x=trace3$error_x, error_y=trace3$error_y, error_z=trace3$error_z, textfont=trace3$textfont) p <- layout(p, font=layout$font, smith=layout$smith, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis, bargap=layout$bargap, boxgap=layout$boxgap, height=layout$height, legend=layout$legend, margin=layout$margin, barmode=layout$barmode, boxmode=layout$boxmode, autosize=layout$autosize, dragmode=layout$dragmode, hovermode=layout$hovermode, titlefont=layout$titlefont, separators=layout$separators, showlegend=layout$showlegend, annotations=layout$annotations, bargroupgap=layout$bargroupgap, boxgroupgap=layout$boxgroupgap, hidesources=layout$hidesources, plot_bgcolor=layout$plot_bgcolor, paper_bgcolor=layout$paper_bgcolor)