Git Product home page Git Product logo

ggworldmap's Introduction

img/header.png

<Description & Motivation>

Inspiration

Installation

library(devtools)
devtools::install_github("thackl/ggworldmap")

Usage

library(tidyverse)
library(ggworldmap)

# a nice projected map with graticules and degree labels
ggworldmap(proj = "moll", degree = list("light", long_by = 80))

# and short for
proj <- "moll"
ggplot() +
  geom_worldmap(proj = proj, color = "gray90", fill = "gray90") +
  geom_graticule(proj = proj, color = "gray80") +
  geom_gratframe(proj = proj, color = "gray80") +
  geom_degree(proj = proj, color = "gray80", long_by = 80) +
  theme_worldmap_light() +
  coord_equal()

ggsave("img/ggworldplot.png", width = 12, height = 6, type = "cairo")

img/ggworldplot.png

# Pacific centered map with colored countries
long_0 <- 110
ggworldmap(proj = "ortho", long_0 = long_0, mapping = aes(fill=group),
    long_min = long_0-90, long_max = long_0+90, color = "black",
    show.legend = FALSE, graticule = list("light", color = "grey20"),
    degree = list("light", long_n = 3, color = "grey30", family = "Times New Roman")) +
  scale_fill_distiller(palette = "Pastel2")

ggsave("img/east-asia-countries.png", width = 12, height = 6, type = "cairo")

img/east-asia-countries.png

# The Pacific Ring of Fire
data(volcanic_eruptions)            # load example data
proj <- "robin"                     # Robinson projection
long_0 <- -150                      # Center on Pacific
ve_proj <- volcanic_eruptions %>%
  project(proj, long_0) %>%         # project data
  arrange(desc(VEI))                # and get nice plotting order
# plot projected map and data
ggworldmap(ve_proj, long_0 = long_0, proj = proj) +
  geom_point(aes(size = VEI^4, color = VEI), alpha =.5) +
  scale_color_distiller(palette = "Spectral")

ggsave("img/pacific-ring-of-fire.png", width = 12, height = 6, type = "cairo")

img/pacific-ring-of-fire.png

# TODO: Project and Concentrate Data
proj <- "robin" # use Robinson projection
long_0 <- -120  # center on Pacific
lat_min <- -70  # and clip the poles
lat_max <- 70

# get some sample data
data(volcanic_eruptions)
volcanic_eruptions <- volcanic_eruptions %>%
  filter(Year > 1919) %>%          # let's look at last 100 years
  project(proj, long_0)            # and we want our data projected
volcanic_eruptions_decluttered <- volcanic_eruptions %>%
  concentrate(lambda = .2) %>%     # round up close points at a single location
  arrange(Type)                    # and order them nicely for plotting


# set up a plot of the world
gg <- ggplot(mapping = aes(x=long, y=lat)) +
  # ----------------------------------------------------------------------------
  # get a world map, centered on the Pacific, in Robinson projection
  geom_worldmap(proj = proj, long_0 = long_0, lat_min = lat_min,
    lat_max = lat_max, color = "grey90", fill = "grey90") +
  # add some grid lines
  geom_graticule(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
    long_by = 40, linetype = 1, color = "grey80", size = .5, alpha=.3) +
  # and a grid frame
  geom_graticule(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
     lat_n = 2, long_n = 2, linetype = 1, color = "grey80", size = 1) +
  # and some grid labels
  geom_degree(proj = proj, long_0 = long_0, lat_min = lat_min, lat_max = lat_max,
    long_by = 40, color = "grey60", size = 3)
  # ----------------------------------------------------------------------------
  # now throw our data on the canvas
  geom_array(aes(color = Type), volcanic_eruptions_decluttered, nrow = 7, spread = 2,
    shape = 19, size = .8, vjust = .5) +
  # original locations with overplotting issues
  geom_point(data = volcanic_eruptions, size = .3, alpha = .5) +
  # ----------------------------------------------------------------------------
  # and finally make things pretty
  ggtitle("Significant Volcanic Eruptions", "of the last 100 years by most common types") +
  # with fixed aspect ratio, but no poles,
  coord_equal(ylim = c(-80, 80)) +
  # an almost void greyish theme,
  theme_light(base_size = 15) + theme(
    panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
    axis.text = element_blank(), axis.ticks = element_blank(), axis.title = element_blank(),
    legend.justification=c(0,1), legend.position=c(.52,.29), legend.text.align=0) +
  # and nice colors
  scale_color_brewer("Eruption types", palette="Dark2") +
  # wrapped in facets
  facet_wrap(~Type, ncol=2, strip.position = "left")

img/volcanic-eruptions.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.