# Get this figure: fig <- get_figure("etav3", 49) # Get this figure's data: data <- get_figure("etav3", 49)$data # Add data to this figure: p <- add_trace(p, x=c(4, 5), y=c(4, 5), kwargs=list(filename="Cigarette Brand Preference by Country", fileopt="extend")) # Get z data of first trace: z1 <- get_figure("etav3", 49)$data[[1]]$z # 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 = "48e8af", type = "choropleth", zmax = 25, zmin = 1, z = c("6", "1", "30", "30", "1", "30", "1", "30", "1", "1", "1", "30", "1", "1", "1", "30", "1", "1", "1", "1", "2", "4", "1", "1", "1", "2", "2", "1", "1", "1", "1", "2", "1", "1", "1", "2", "6", "1", "3", "6", "30", "2", "30", "1", "30", "1", "1", "4", "30", "1", "2", "1", "30", "1", "3", "30", "30", "1", "1", "2", "1", "1", "1", "30", "1", "30", "30", "6", "30", "1", "1", "1", "2", "30", "1", "1", "1", "1", "30", "1", "4", "3", "2", "30", "1", "30", "1", "1", "30", "6", "1", "30", "6", "2", "30", "2", "2", "30", "1", "1", "1", "30", "1", "1", "30", "30", "1", "1", "1", "2", "1", "1", "1", "30", "1", "30", "1", "4", "1", "1", "1", "1"), zauto = FALSE, text = c("L & M", "Rym", "Marlboro", "Marlboro", "Winfield", "Marlboro", "West", "Marlboro", "BAT Bangladesh", "Embassy", "Neman brands", "Marlboro", "Casino", "Drina", "Derby", "Marlboro", "Victory", "London KS", "Ara", "Diplomat Menthol", "Du Maurier", "Belmont", "Chunghwa", "Boston", "Tumbaco", "Delta", "Excellence", "Ronhill", "Popular", "Rothmans Royals", "Start", "Prince", "Nacional", "Lider Suave", "Cleopatra", "Delta", "L & M", "Nyala", "Benson & Hedges", "L & M", "Marlboro", "Viceroy", "Marlboro", "London", "Marlboro", "Rubios", "Bristol", "Belmont", "Marlboro", "Soplanae", "Winston", "Wills Gold Flake", "Marlboro", "57", "Benson & Hedges", "Marlboro", "Marlboro", "Craven A", "Mild Seven", "Viceroy", "Sovereign", "Sportsman", "Esse", "Marlboro", "Rdaeng", "Marlboro", "Marlboro", "L & M", "Marlboro", "Rodeo", "Dunhill", "Rothmans", "State Express 555", "Marlboro", "Temp", "Classic", "Marquise", "Khukuri", "Marlboro", "Holiday", "Belmont", "Benson & Hedges", "Prince", "Marlboro", "Morven Gold", "Marlboro", "Kentucky", "Hamilton", "Marlboro", "L & M", "SG", "Marlboro", "L & M", "Winston", "Marlboro", "Excellence", "State Express 555", "Marlboro", "Golden Gate", "Boss", "Peter Stuyvesant", "Marlboro", "Gold Leaf", "Bringi", "Marlboro", "Marlboro", "Al Sherek", "Sweet Menthol", "Krong Thip", "Du Maurier", "20 Mars", "Samsun", "Prilucky Osoblyvi", "Marlboro", "Lambert & Butler", "Marlboro", "Nevada", "Belmont", "Vinataba", "Kamaran", "Consulate", "Madison"), visible = TRUE, colorbar = list( x = 0.98, y = 0.5, ticks = "", title = "Frequency of Cigarette Brand", tickfont = list(family = "Balto, sans-serif"), thickness = 20, outlinecolor = "rgb(255, 255, 255)", showticklabels = TRUE ), hoverinfo = "all", colorscale = list(c(0, "rgb(220, 220, 220)"),list(0.2, "rgb(245, 195, 157)"),list(0.4, "rgb(245, 160, 105)"),list(1, "rgb(178, 10, 28)")), locationmode = "country names", locations = c("Albania", "Algeria", "Andorra", "Argentina", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Bolivia", "Bosnia and Herzegovina", "Brazil", "Brunei", "Bulgaria", "Burma", "Cambodia", "Cameroon", "Canada", "Chile", "China", "Colombia", "Congo, Democratic Republic of the", "Costa Rica", "Côte d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Georgia", "Germany", "Ghana", "Greece", "Guatemala", "Guyana", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Korea, South", "Kuwait", "Laos", "Latvia", "Lebanon", "Lithuania", "Luxembourg", "Macedonia", "Malaysia", "Malta", "Mauritius", "Mexico", "Moldova", "Montenegro", "Morocco", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Saudi Arabia", "Senegal", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Sweden", "Switzerland", "Syria", "Tanzania", "Thailand", "Trinidad and Tobago", "Tunisia", "Turkey", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe"), reversescale = FALSE, autocolorscale = FALSE ) data <- list(trace1) layout <- list( geo = list( bgcolor = "rgba(197, 176, 72, 0.7)", showland = TRUE, landcolor = "rgba(240, 220, 130, 0.54)", showocean = TRUE, framecolor = "rgba(197, 176, 72, 0.7)", framewidth = 0.5, oceancolor = "rgba(51, 153, 255, 0.41)" ), font = list(family = "Courier New, monospace"), title = "Cigarette Brand Preference by Country", width = 1022, height = 566, autosize = TRUE, paper_bgcolor = "rgba(197, 176, 72, 0.2)" ) p <- plot_ly() p <- add_trace(p, uid=trace1$uid, type=trace1$type, zmax=trace1$zmax, zmin=trace1$zmin, z=trace1$z, zauto=trace1$zauto, text=trace1$text, visible=trace1$visible, colorbar=trace1$colorbar, hoverinfo=trace1$hoverinfo, colorscale=trace1$colorscale, locationmode=trace1$locationmode, locations=trace1$locations, reversescale=trace1$reversescale, autocolorscale=trace1$autocolorscale) p <- layout(p, geo=layout$geo, font=layout$font, title=layout$title, width=layout$width, height=layout$height, autosize=layout$autosize, paper_bgcolor=layout$paper_bgcolor)