Black Lives Matter. Please consider donating to Black Girls Code today.

World Map Displaying at USA Scope

I am creating two different plotly maps one at the USA scope and the other at the world scope. The USA scope works and loads as expected but when I then try to create the world map from the same script file in r it leaves the scope at the US and won’t upload to the plotly server

Code is as follows for both maps:

#myQ Page Views by Location for US
myQpageviewslocations <-myQ.page4weeks.location.ga.data
myQpageviewsUS <- sqldf(“SELECT * from myQpageviewslocations where country in (‘United States’ )”)
myQpageviewsUSSStateCounts <- aggregate(pageviews ~ region, data = myQpageviewsUS, FUN = sum)
myQpageviewsUS2 <- merge(states_map, myQpageviewsUSSStateCounts, by.x=“region”, by.y=“region”)

myQpageviewsUSSStateCounts$state_codes <- state.abb[match(myQpageviewsUSSStateCounts$region, state.name)]

myQpageviewsUSMap <- list(
scope = ‘usa’,
projection = list(type = ‘albers usa’),
lakecolor = toRGB(‘white’)
)

myQpageviewsUSMap <- plot_ly(z = myQpageviewsUSSStateCounts$pageviews, text = myQpageviewsUSSStateCounts$region, locations = myQpageviewsUSSStateCounts$state_codes,
type = ‘choropleth’, locationmode = ‘USA-states’) %>%
colorbar(title = “Page Views Per State”) %>%
layout(title = ‘myQVC Page Views by State
(Hover for details)’,geo = g)
myQpageviewsUSMap

#myQ Page Views by Location World Map
myQpageviewslocations <-myQ.page4weeks.location.ga.data
myQpageviewsCountryCounts <- aggregate(pageviews ~ country, data = myQpageviewslocations, FUN = sum)
countrycodes <- countrycode(myQpageviewsCountryCounts$country,‘country.name’, ‘iso3c’)
myQpageviewsCountryCounts$countryIsoCodes <-countrycodes

myQpageviewsWorldMap <- list(
scope =‘world’,
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = ‘Mercator’)
)

myQpageviewsWorldMap <- plot_geo(myQpageviewsCountryCounts) %>%
add_trace(z = myQpageviewsCountryCounts$pageviews, text = myQpageviewsCountryCounts$countryIsoCode, locations = myQpageviewsCountryCounts$countryIsoCode,
type = ‘choropleth’, locationmode = ‘ISO-3’) %>%
colorbar(title = “Page Views Per Country”) %>%
layout(title = ‘myQVC Page Views by Country
(Hover for details)’,geo = g)
myQpageviewsWorldMap

Data set for map that is not working is as follows(myQpageviewsCountryCounts):
country pageviews countryIsoCodes
1 France 3115 FRA
2 Germany 61293 DEU
3 Ireland 1 IRL
4 Italy 21620 ITA
5 Japan 35064 JPN
6 Netherlands 19 NLD
7 Poland 7 POL
8 Spain 1 ESP
9 United Arab Emirates 3 ARE
10 United Kingdom 57165 GBR
11 United States 972642 USA

Solved this already…