if (requireNamespace("maps", quietly = TRUE)) {
        ## Start with plot
        p_map <- l_plot()

        ## Maps from the map library
        canada <- maps::map("world",  "Canada", fill=TRUE, plot=FALSE)

        landcol <- "cornsilk"
        ## Add the map
        id <- l_layer(p_map, canada,
                      color = landcol,
                      index = "end")
        l_scaleto_layer(p_map, id)

        # Get the lakes:
        cdn.lakes <-  maps::map("lakes",
                            fill=TRUE)$names[c(7,8,27, #great
                                               22, 25,
                                               82, 85

        # Add them
        lakecol ="lightblue"
        great.lakes.layer <-  l_layer(p_map,
                                      maps::map("lakes", cdn.lakes,
                                           plot=FALSE, fill=TRUE),
                                      label = "Great Lakes Water",
                                      color = lakecol,
                                      index="end"    # Add the layer at the end so we know
                                      # where it is

        # Move the lake layer up to be above the land map
        l_layer_raise(p_map, great.lakes.layer)

        readline("press the return key to continue: next add points to scatterplot")

        canada.cities <- subset(maps::world.cities,
                                grepl("canada", country.etc ,

             l_configure(p_map, x=long, y=lat,  color = "red"))

        readline("press the return key to continue: next add city name glyphs")

        g.t <- l_glyph_add_text(p_map, text=canada.cities$name)
        p_map['glyph'] <- g.t


Try the loon package in your browser

Any scripts or data that you put into this service are public.

loon documentation built on June 14, 2021, 9:07 a.m.