Note that there are some explanatory texts on larger screens.

plurals
  1. POWorld map with R?
    primarykey
    data
    text
    <p>I have an array that tells me the number of observations per country.</p> <pre><code>countries &lt;- structure(c(532L, 3L, 1L, 15L, 1L, 1L, 2L, 3L, 16L, 2L, 43L, 1L, 2L, 2L, 1L, 1L, 1L, 3L, 2L, 1L, 4L, 4L, 16L, 13L, 2L, 2L, 9L, 1L, 1L, 5L, 3L, 5L, 1L, 1L, 3L, 1L, 10L, 11L, 4L, 2L, 1L, 7L, 1L, 2L, 6L, 7L, 1L, 6L, 1L, 2L, 7L, 1L, 20L, 1L, 2L, 1L, 3L, 2L, 5L, 76L, 2L, 1L, 1L), .Dim = 63L, .Dimnames = structure(list( c("United States", "Argentina", "Armenia", "Australia", "Austria", "Bangladesh", "Belarus", "Belgium", "Brazil", "Bulgaria", "Canada", "Chile", "China", "Colombia", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Dominican Republic", "Ecuador", "Estonia", "France", "Germany", "Greece", "Guatemala", "Hong Kong", "India", "Indonesia", "Iran", "Ireland", "Israel", "Italy", "Kazakhstan", "Kenya", "Latvia", "Malaysia", "Mexico", "Netherlands", "New Zealand", "Norway", "Peru", "Philippines", "Poland", "Portugal", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sweden", "Switzerland", "Thailand", "Turkey", "Ukraine", "United Kingdom", "Uruguay", "Uzbekistan", "Venezuela" )), .Names = "")) </code></pre> <p>I am able to plot a map using the maps library. But I would appreciate the help in making it look better.</p> <pre><code>library(maps) map(database="world") map(database="world", col=countries, fil=countries) legend("topleft", fill = countries, legend = countries, col = countries) box() </code></pre> <p>The first big problem is the legend. A continuous scale would probably look better than one color per country, not sure how to do that. After fixing that, anything that can be done to make it look better would be much appreciated. </p> <p>Thanks!</p> <hr> <p>I can make a dynamic map using googleVis, but I'm having troubles with making an static map using ggplot2. For example, with ggplot2 it looks like I have no one in the US.</p> <p>This is my code</p> <pre><code>#Load My data countries &lt;- structure(list(country = c("United States", "Afghanistan", "Albania", "Argentina", "Armenia", "Australia", "Austria", "Bahrain", "Bangladesh", "Belarus", "Belgium", "Bosnia and Herzegovina", "Brazil", "Bulgaria", "Canada", "Chile", "China", "Colombia", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Estonia", "Finland", "France", "Germany", "Greece", "Guatemala", "Haiti", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Ireland", "Israel", "Italy", "Japan", "Jordan", "Kazakhstan", "Kenya", "Korea, South", "Latvia", "Libya", "Lithuania", "Macedonia", "Malaysia", "Malta", "Mexico", "Moldova", "Morocco", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Pakistan", "Panama", "Peru", "Philippines", "Poland", "Portugal", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "Slovenia", "Somalia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sweden", "Switzerland", "Taiwan", "Thailand", "Turkey", "Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay", "Uzbekistan", "Venezuela", "Zimbabwe" ), count = c(1224L, 1L, 1L, 4L, 2L, 40L, 2L, 1L, 2L, 5L, 8L, 2L, 40L, 3L, 106L, 4L, 16L, 10L, 8L, 4L, 2L, 5L, 4L, 5L, 3L, 1L, 2L, 5L, 1L, 10L, 26L, 41L, 3L, 1L, 3L, 2L, 1L, 34L, 2L, 3L, 10L, 4L, 19L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 3L, 1L, 2L, 2L, 36L, 1L, 1L, 31L, 10L, 1L, 1L, 1L, 2L, 6L, 2L, 3L, 29L, 7L, 11L, 13L, 21L, 5L, 9L, 6L, 3L, 2L, 1L, 22L, 2L, 42L, 1L, 3L, 5L, 2L, 6L, 5L, 13L, 2L, 157L, 4L, 1L, 5L, 1L)), .Names = c("country", "count" ), row.names = c(NA, -93L), class = "data.frame") #Make dynamic map library(googleVis) # Make the map! geoMap &lt;- gvisGeoMap(countries, locationvar="country", numvar="count", options=list(dataMode="regions")) plot(geoMap) #Make ggplot2 map library(maps) library(ggplot2) #load world data world &lt;- map_data("world") #Delete Antarctica world &lt;- subset(world,region!="Antarctica") #Add count world$count&lt;-countries$count[match(world$region,countries$country,nomatch=NA)] qplot(long, lat, data = world, group = group, fill=count, geom ="polygon",ylab="",xlab="") </code></pre> <p>Why is the ggplot2 map wrong? How can I fix it?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload