# World Map Displaying at USA Scope

**URL:** <https://community.plotly.com/t/world-map-displaying-at-usa-scope/4204>\
**Category:** Plotly R\
**Created:** [May 11, 2017, 5:53pm UTC](https://community.plotly.com/t/world-map-displaying-at-usa-scope/4204 "2017-05-11T17:53:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![feezie](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@feezie](https://community.plotly.com/u/feezie)\
**Post date:** [May 11, 2017, 5:53pm UTC](https://community.plotly.com/t/world-map-displaying-at-usa-scope/4204/1 "2017-05-11T17:53:55Z")

</div>

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](http://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](http://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

---

<div class="post-metadata">

**Author:** ![feezie](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@feezie](https://community.plotly.com/u/feezie)\
**Post date:** [May 11, 2017, 6:25pm UTC](https://community.plotly.com/t/world-map-displaying-at-usa-scope/4204/2 "2017-05-11T18:25:17Z")

</div>

Solved this already…
