Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is my solution. </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") suppressPackageStartupMessages({ library(maptools) library(ggplot2) }) PolygonCoords &lt;- function(polygon) { polygons &lt;- polygon@Polygons coords.list &lt;- lapply(seq_along(polygons), function(i) { # Extract the group, sequence, area, longitude, and latitude. coords &lt;- polygons[[i]]@coords cbind(i, 1:nrow(coords), polygons[[i]]@area, coords) }) coords.df &lt;- as.data.frame(do.call(rbind, coords.list)) names(coords.df) &lt;- c("order", "seq", "area", "long", "lat") return(coords.df) } ConvertWorldSimple &lt;- function(mapdata, min.area = 0) { # min.area is the minimum size of the polygons. Setting to some # positive value will filter out tiny islands. coords.list &lt;- lapply(mapdata@polygons, PolygonCoords) ncoords &lt;- sapply(coords.list, nrow) coords.df &lt;- do.call(rbind, coords.list) coords.df$country &lt;- rep(mapdata@data$NAME, ncoords) country.group &lt;- factor(paste(coords.df$country, coords.df$order)) coords.df$group &lt;- as.numeric(country.group) coords.df &lt;- coords.df[coords.df$area &gt;= min.area, ] return(coords.df) } data("wrld_simpl") world &lt;- ConvertWorldSimple(wrld_simpl, min.area = 0.1) #Delete Antarctica world &lt;- subset(world,country!="Antarctica") #Add count world$count&lt;-countries$count[match(world$country,countries$country,nomatch=NA)] x&lt;-quantile(world$count, na.rm=TRUE) qplot(long, lat, data = world, group = group, fill=count, geom ="polygon",ylab="",xlab="") + scale_fill_gradient(name="log(Number of\nStudents)", trans = "log") </code></pre> <p>Thanks for the help!</p>
 

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