# Get this figure: fig <- get_figure("Dreamshot", 2565)
# Get this figure's data: data <- get_figure("Dreamshot", 2565)$data
# Add data to this figure: p <- add_trace(p, x=c(4, 5), y=c(4, 5), kwargs=list(filename="Population Trends", fileopt="extend"))
# Get y data of first trace: y1 <- get_figure("Dreamshot", 2565)$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 = "e47b54",
line = list(
color = "rgb(148, 103, 189)",
shape = "spline",
width = 4
),
mode = "lines",
name = "North America",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c(0.18691588785046953, 0.2429906542056095, 0.2803738317757034, 0.3364485981308416, 0.35514018691588944, 0.3925233644859816, 0.4299065420560755, 0.44859813084112155, 0.4859813084112172, 0.5046728971962633, 0.5046728971962633, 0.5233644859813094)
)
trace2 <- list(
uid = "62c2fe",
line = list(
shape = "spline",
width = 4
),
mode = "lines",
name = "Latin America & the Caribbean",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("0.18691588785046953", "0.2990654205607495", "0.4112149532710294", "0.5420560747663572", "0.6168224299065432", "0.7102803738317771", "0.7663551401869171", "0.803738317757011", "0.803738317757011", "0.7850467289719631", "0.7663551401869171", "0.747663551401871")
)
trace3 <- list(
uid = "b31779",
line = list(
color = "rgb(255, 0, 255)",
shape = "spline",
width = 4
),
mode = "lines",
name = "Africa",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("0.2429906542056095", "0.3925233644859816", "0.5794392523364493", "0.822429906542057", "1.1028037383177587", "1.4953271028037385", "1.925233644859814", "2.3177570093457955", "2.7476635514018692", "3.4018691588785064", "3.794392523364486", "4.186915887850468")
)
trace4 <- list(
uid = "48ee99",
line = list(
color = "rgb(106, 168, 79)",
shape = "spline",
width = 4
),
mode = "lines",
name = "Asia",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("1.4018691588785064", "2.1682242990654217", "2.953271028037383", "3.738317757009346", "4.261682242990656", "4.691588785046731", "5.028037383177571", "5.158878504672899", "5.158878504672899", "5.028037383177571", "4.897196261682245", "4.728971962616823")
)
trace5 <- list(
uid = "4341c8",
line = list(
color = "rgb(67, 67, 67)",
shape = "spline",
width = 4
),
mode = "lines",
name = "World",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("2.5607476635514015", "3.8130841121495322", "4.915887850467291", "6.205607476635516", "7.177570093457946", "8", "8.971962616822431", "9.532710280373834", "10.037383177570096", "10.52336448598131", "10.766355140186917", "10.971962616822431")
)
trace6 <- list(
uid = "a81a70",
line = list(
color = "rgba(106, 168, 79, 0)",
shape = "spline",
width = 4
),
mode = "lines",
name = "95% C.I.",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("2.5607476635514015", "3.8130841121495322", "4.915887850467291", "6.205607476635516", "7.177570093457946", "8.074766355140188", "9.177570093457945", "9.869158878504674", "10.560747663551403", "11.401869158878505", "11.88785046728972", "12.448598130841122"),
showlegend = FALSE
)
trace7 <- list(
uid = "f1e76f",
fill = "tonexty",
line = list(
color = "rgba(217, 217, 217, 0)",
shape = "spline",
width = 4
),
mode = "lines",
name = "95% C.I.",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("2.5607476635514015", "3.8130841121495322", "4.915887850467291", "6.205607476635516", "7.177570093457946", "7.925233644859814", "8.766355140186917", "9.233644859813085", "9.55140186915888", "9.757009345794394", "9.77570093457944", "9.700934579439252"),
showlegend = FALSE
)
trace8 <- list(
uid = "7aec79",
line = list(
color = "rgb(61, 133, 198)",
shape = "spline",
width = 4
),
mode = "lines",
name = "Europe",
type = "scatter",
x = c("1952-3-8", "1972-4-30", "1986-11-23", "2000-12-21", "2012-11-12", "2025-9-24", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("0.5607476635514033", "0.6542056074766354", "0.7102803738317771", "0.747663551401871", "0.747663551401871", "0.747663551401871", "0.7289719626168232", "0.7102803738317771", "0.691588785046731", "0.6728971962616832", "0.6542056074766354", "0.6542056074766354")
)
trace9 <- list(
uid = "91fe66",
line = list(
dash = "dot",
color = "rgb(102, 102, 102)",
shape = "spline",
width = 4
),
mode = "lines",
name = "World (old projection)",
type = "scatter",
x = c("2000-9-23", "2018-12-7", "2036-5-29", "2051-12-11", "2067-12-19", "2081-10-19", "2098-4-22"),
y = c("6.149532710280376", "7.551401869158879", "8.504672897196262", "8.971962616822431", "9.102803738317757", "8.953271028037385", "8.485981308411215")
)
trace10 <- list(
uid = "cb36b6",
line = list(
color = "rgba(23, 190, 207, 0)",
shape = "spline",
width = 4
),
mode = "lines",
name = "C.I.",
type = "scatter",
x = c("", "", "", "", "", "", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("", "", "", "", "", "", "9.1176", "10.204213357238903", "10.960824742268038", "11.791035410129984", "12.584311967727473", "13.340385477364407"),
showlegend = FALSE
)
trace11 <- list(
uid = "02f2d9",
fill = "tonexty",
line = list(
color = "rgba(31, 119, 180, 0)",
shape = "spline",
width = 4
),
mode = "lines",
name = "C.I.",
type = "scatter",
x = c("", "", "", "", "", "", "2038-11-2", "2049-7-8", "2060-9-6", "2073-10-15", "2085-3-13", "2098-7-19"),
y = c("", "", "", "", "", "", "8.766355140186917", "9.109636934110261", "9.291169878978035", "9.378574630210666", "9.30004482294935", "9.090900941281934"),
fillcolor = "rgba(217, 217, 217, 0.5)",
showlegend = FALSE
)
data <- list(trace1, trace2, trace3, trace4, trace5, trace6, trace7, trace8, trace9, trace10, trace11)
layout <- list(
title = "
World Population Projections",
width = 700,
xaxis = list(
type = "date",
range = c(-562262400000, 4056591600000),
title = "Source: Scientific American",
showgrid = FALSE,
showline = TRUE,
zeroline = FALSE,
autorange = TRUE
),
yaxis = list(
side = "right",
type = "linear",
range = c(-0.5438324226780826, 14.07113378789296),
title = "Total Population (billions)",
showgrid = FALSE,
showline = TRUE,
zeroline = FALSE,
autorange = TRUE
),
height = 800,
legend = list(
x = 0.0171875,
y = 1.019047619047619
),
autosize = FALSE,
showlegend = FALSE,
annotations = list(
list(
x = 3617415457291.667,
y = 11.368150789808851,
text = "World
(new projection)",
showarrow = FALSE,
textangle = 0
),
list(
x = 960505228125,
y = 4.362620519442196,
font = list(color = "rgb(106, 168, 79)"),
text = "Asia",
showarrow = FALSE,
textangle = -30
),
list(
x = 1891492987500,
y = 2.100780510663344,
font = list(color = "rgb(255, 0, 255)"),
text = "Africa",
showarrow = FALSE,
textangle = -20
),
list(
x = 217158412500,
y = 1.056854352765412,
font = list(color = "rgb(61, 133, 198)"),
text = "Europe",
showarrow = FALSE
),
list(
x = 3161677837500,
y = 1.2656395843449983,
font = list(color = "rgb(255, 127, 14)"),
text = "Latin America and the Caribbean",
showarrow = FALSE
),
list(
x = 1913143865625,
y = 0.012928194867480869,
font = list(color = "rgb(148, 103, 189)"),
text = "North America",
showarrow = FALSE
),
list(
x = 2132058300000,
y = 8.380052475481655,
ax = -13,
ay = 66,
text = "Dotted Line:
International Institute
for Applied Systems
Analysis 2001 projection",
arrowhead = 0
),
list(
x = 935379517708.3333,
y = 6.404450284190945,
ax = -31,
ay = -37,
text = "Solid Lines:
U.N. 2014
projections",
arrowhead = 0
),
list(
x = 3047275666666.667,
y = 8.673025300440106,
text = "World
(old projection)",
showarrow = FALSE
)
)
)
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)
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)
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)
p <- add_trace(p, uid=trace4$uid, line=trace4$line, mode=trace4$mode, name=trace4$name, type=trace4$type, x=trace4$x, y=trace4$y)
p <- add_trace(p, uid=trace5$uid, line=trace5$line, mode=trace5$mode, name=trace5$name, type=trace5$type, x=trace5$x, y=trace5$y)
p <- add_trace(p, uid=trace6$uid, line=trace6$line, mode=trace6$mode, name=trace6$name, type=trace6$type, x=trace6$x, y=trace6$y, showlegend=trace6$showlegend)
p <- add_trace(p, uid=trace7$uid, fill=trace7$fill, line=trace7$line, mode=trace7$mode, name=trace7$name, type=trace7$type, x=trace7$x, y=trace7$y, showlegend=trace7$showlegend)
p <- add_trace(p, uid=trace8$uid, line=trace8$line, mode=trace8$mode, name=trace8$name, type=trace8$type, x=trace8$x, y=trace8$y)
p <- add_trace(p, uid=trace9$uid, line=trace9$line, mode=trace9$mode, name=trace9$name, type=trace9$type, x=trace9$x, y=trace9$y)
p <- add_trace(p, uid=trace10$uid, line=trace10$line, mode=trace10$mode, name=trace10$name, type=trace10$type, x=trace10$x, y=trace10$y, showlegend=trace10$showlegend)
p <- add_trace(p, uid=trace11$uid, fill=trace11$fill, line=trace11$line, mode=trace11$mode, name=trace11$name, type=trace11$type, x=trace11$x, y=trace11$y, fillcolor=trace11$fillcolor, showlegend=trace11$showlegend)
p <- layout(p, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis, height=layout$height, legend=layout$legend, autosize=layout$autosize, showlegend=layout$showlegend, annotations=layout$annotations)