map function - RDocumentation (2024)

Description

Draw lines and polygons as specified by a map database.

Usage

map(database = "world", regions = ".", exact = FALSE, boundary = TRUE, interior = TRUE, projection = "", parameters = NULL, orientation = NULL, fill = FALSE, col = 1, plot = TRUE, add = FALSE, namesonly = FALSE, xlim = NULL, ylim = NULL, wrap = FALSE, resolution = if (plot) 1 else 0, type = "l", bg = par("bg"), mar = c(4.1, 4.1, par("mar")[3], 0.1), myborder = 0.01, namefield="name", lforce="n", ...)

Value

If plot = TRUE, a plot is made where the polygons selected from database, through the

regions, xlim, and ylim arguments, are outlined (fill is FALSE) or filled (fill is TRUE) with the colors in col.

The return value is a list with

x, y, range, and names components. This object can be used as a database for successive calls to map and functions. If fill is FALSE, the x and y vectors are the coordinates of successive polylines, separated by NAs. If

fill is TRUE, the x and y vectors have coordinates of successive polygons, again separated by NAs. Thus the return value can be handed directly to lines or

polygon, as appropriate.

When namesonly is TRUE, only the names component is returned.

After a call to map for which the projection argument was specified there will be a global variable .Last.projection

containing information about the projection used. This will be consulted in subsequent calls to map which use

projection = ''.

Arguments

database

character string naming a geographical database, a list of x, y, and names obtained from a previous call to map or a spatial object of class SpatialPolygons or SpatialLines. The string choices include a world map, three USA databases (usa, state, county), and more (type help(package='maps') to see the package index). If the requied database is in a different package that has not been attached, the string may be started with "packagename::". The location of the map databases may be overridden by setting the R_MAP_DATA_DIR environment variable.

regions

character vector that names the polygons to draw. Each database is composed of a collection of polygons, and each polygon has a unique name. When a region is composed of more than one polygon, the individual polygons have the name of the region, followed by a colon and a qualifier, as in michigan:north and michigan:south. Each element of regions is matched against the polygon names in the database and, according to exact, a subset is selected for drawing. The regions may also be defined using (perl) regular expressions. This makes it possible to use 'negative' expressions like "Norway(?!:Svalbard)", which means Norway and all islands except Svalbard. All entries are case insensitive. The default selects all polygons in the database.

exact

If TRUE, only exact matches with regions are selected for drawing. If FALSE, each element of regions is matched as a regular expression against the polygon names in the database and all matches are selected for drawing.

boundary

If FALSE, boundary segments are not drawn. A boundary segment is a line segment of the map that bounds only one of the polygons to be drawn. This argument is ignored if fill is TRUE.

interior

If FALSE, interior segments are not drawn. An interior segment is a line segment of the map that bounds two of the polygons to be drawn. This argument is ignored if fill is TRUE.

projection

character string that names a map projection to use. See mapproject (in the mapproj library). The default is to use a rectangular projection with the aspect ratio chosen so that longitude and latitude scales are equivalent at the center of the picture.

parameters

numeric vector of parameters for use with the projection argument. This argument is optional only in the sense that certain projections do not require additional parameters. If a projection does require additional parameters, these must be given in the parameters argument.

orientation

a vector c(latitude, longitude, rotation) describing where the map should be centered and a clockwise rotation (in degrees) about this center.

fill

logical flag that says whether to draw lines or fill areas. If FALSE, the lines bounding each region will be drawn (but only once, for interior lines). If TRUE, each region will be filled using colors from the col = argument, and bounding lines are drawn by default using par("fg"). To hide the bounding lines, use border=NA (see ...).

col

vector of colors. If fill is FALSE, the first color is used for plotting all lines, and any other colors are ignored. Otherwise, the colors are matched one-one with the polygons that get selected by the region argument (and are reused cyclically, if necessary). If fill = TRUE, the default boundary line colour is given by par("fg"). To change this, you can use the border argument (see '...'). A color of NA causes the corresponding region to be deleted from the list of polygons to be drawn. Polygon colors are assigned after polygons are deleted due to values of the xlim and ylim arguments.

plot

logical flag that specifies whether plotting should be done. If plot is TRUE the return value of map will not be printed automatically .

add

logical flag that specifies whether to add to the current plot. If FALSE, a new plot is begun, and a new coordinate system is set up.

namesonly

If TRUE, the return value will be a character vector of the names of the selected polygons. See the Value section below.

xlim

two element numeric vector giving a range of longitudes, expressed in degrees, to which drawing should be restricted. Longitude is measured in degrees east of Greenwich, so that, in particular, locations in the USA have negative longitude. If fill = TRUE, polygons selected by region must be entirely inside the xlim range. The default value of this argument spans the entire longitude range of the database.

ylim

two element numeric vector giving a range of latitudes, expressed in degrees, to which drawing should be restricted. Latitude is measured in degrees north of the equator, so that, in particular, locations in the USA have positive latitude. If fill = TRUE, polygons selected by region must be entirely inside the ylim range. The default value of this argument spans the entire latitude range of the database.

wrap

Boolean or a numeric vector. If TRUE, lines that cross too far across the map (due to a strange projection) are omitted. If wrap is a vector of length 2 or more, it is interpreted as the longitude range to be used for a global map, e.g. c(-180,180) or c(0,360). This wrapping even works when fill=TRUE and is performed before any projection (so the range must always be in degrees). However, the wrapping is performed after xlim, ylim are applied, so these options should probably never be combined. If there is a third component, this signifies the latitude at which Antarctica will be "closed". The default value is -89.9. Special values are NA (don't draw Antarctica at all) and 0 (draw the line at the latitude of the extremal points, not at a fixed lower latitude).

resolution

number that specifies the resolution with which to draw the map. Resolution 0 is the full resolution of the database. Otherwise, just before polylines are plotted they are thinned: roughly speaking, successive points on the polyline that are within resolution device pixels of one another are collapsed to a single point (see the Reference for further details). Thinning is not performed if plot = FALSE or when polygons are drawn (fill = TRUE or database is a list of polygons).

type

character string that controls drawing of the map. Aside from the default type = "l", the value type = "n" can be used to set up the coordinate system and projection for a map that will be added to in later calls.

bg

background color.

mar

margins, as in par. Defaults allow for map.axes().

myborder

scalar or vector of length 2 specifying the porportion of the plot to add to the defined or computed limits as borders.

namefield

A vector of column names to be used as region name if database is a SpatialPolygonsDataFrame. Ignored in all other cases.

lforce

Limit enforcement. Only taken into account if xlim and/or ylim are defined and (for "s" and "l") a projection is used. Possible values are "n" (none) "e" (exact),"s" (small),"l" (large). If lforce="e", map data is restricted exactly to the given limits prior to projection. This option affects the output value of the map, not only the plot window.If lforce="s", the four corners defined by xlim and ylim are projected and the plot window is restricted to the largest rectangle inside this region. "l" will result in a larger rectangle that includes the four corners. However, the parts that fall outside the original limits may not be complete (only polygons that partially fall inside the boundaries are included). This will also work with fill=TRUE. In this case the output value of the data is not changed, only the plot window is affected. These options are only useful for some projections.

...

Extra arguments passed to polygon or lines. Of particular interest may be the options border andlty that control the color and line type of the polygon borders when fill = TRUE.

Details

The simplest form of use of this function is:

map(mymap)

where mymap is the returned value from a previous call tomap().

References

Richard A. Becker, and Allan R. Wilks, "Maps in S", AT&T Bell Laboratories Statistics Research Report [93.2], 1993. https://web.archive.org/web/20050825145143/http://www.research.att.com/areas/stat/doc/93.2.ps

Richard A. Becker, and Allan R. Wilks, "Constructing a Geographical Database", AT&T Bell Laboratories Statistics Research Report [95.2], 1995. https://web.archive.org/web/20050825145143/http://www.research.att.com/areas/stat/doc/95.2.ps

See Also

map.text, map.axes, map.scale, map.grid (in the mapproj library), polygon, SpatialPolygons2map

Examples

Run this code

map()# low resolution map of the worldmap(wrap = c(0,360), fill = TRUE, col = 2) # pacific-centered map of the worldmap(wrap = c(0, 360, NA), fill = TRUE, col = 2) # idem, without Antarcticamap('usa')# national boundariesmap('county', 'new jersey')# county map of New Jerseymap('state', region = c('new york', 'new jersey', 'penn'))# map of three statesmap("state", ".*dakota", myborder = 0)# map of the dakotasmap.axes()# show the effect of myborder = 0if(require(mapproj)) map('state', proj = 'bonne', param = 45)# Bonne equal-area projection of states# names of the San Juan islands in Washington statemap('county', 'washington,san', names = TRUE, plot = FALSE)# national boundaries in one linetype, states in another# (figure 5 in the reference)map("state", interior = FALSE)map("state", boundary = FALSE, lty = 2, add = TRUE)# plot the ozone data on a base map# (figure 4 in the reference)data(ozone)map("state", xlim = range(ozone$x), ylim = range(ozone$y))text(ozone$x, ozone$y, ozone$median)box()if(require(mapproj)) {# mapproj is used for projection="polyconic" # color US county map by 2009 unemployment rate # match counties to map using FIPS county codes # Based on J's solution to the "Choropleth Challenge" # http://blog.revolutionanalytics.com/2009/11/choropleth-challenge-result.html # load data # unemp includes data for some counties not on the "lower 48 states" county # map, such as those in Alaska, Hawaii, Puerto Rico, and some tiny Virginia # cities data(unemp) data(county.fips) # define color buckets colors = c("#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043") unemp$colorBuckets <- as.numeric(cut(unemp$unemp, c(0, 2, 4, 6, 8, 10, 100))) leg.txt <- c("<2%", "2-4%", "4-6%", "6-8%", "8-10%", ">10%") # align data with map definitions by (partial) matching state,county # names, which include multiple polygons for some counties cnty.fips <- county.fips$fips[match(map("county", plot=FALSE)$names, county.fips$polyname)] colorsmatched <- unemp$colorBuckets [match(cnty.fips, unemp$fips)] # draw map map("county", col = colors[colorsmatched], fill = TRUE, resolution = 0, lty = 0, projection = "polyconic") map("state", col = "white", fill = FALSE, add = TRUE, lty = 1, lwd = 0.2, projection="polyconic") title("unemployment by county, 2009") legend("topright", leg.txt, horiz = TRUE, fill = colors) # Choropleth Challenge example, based on J's solution, see: # http://blog.revolutionanalytics.com/2009/11/choropleth-challenge-result.html # To see the faint county boundaries, use RGui menu: File/SaveAs/PDF}

Run the code above in your browser using DataLab

map function - RDocumentation (2024)

FAQs

What does the map function do in R? ›

The Map function in R is an efficient way to perform operations across multiple vectors or lists. the Map function in R is a powerful tool for applying a function to corresponding elements of multiple vectors or lists. It allows for efficient and concise operations across multiple data structures.

What does the map () function do? ›

The map() function executes a specified function for each item in an iterable. The item is sent to the function as a parameter.

What package is map() in R? ›

The map() function from the purrr package in R can be used to apply some function to each element in a vector or list and return a list as a result.

What are the arguments for map function in JavaScript? ›

A function is the first argument accepted by the map() method. It is a required argument containing the code you want the computer to invoke for each item of the calling array. Keep in mind that map() 's function argument accepts three parameters: currentItem , index , and an array .

What type of object does map () return in R? ›

map() Always returns a list, and the elements of the list may be of different types. This is quite similar to the Base R function lapply .

What is the benefit of map function? ›

Why Use the JavaScript Map() Function?
  • Speed: Map() is quicker for adding or removing data.
  • Flexibility: You can use different types of data as keys.
  • Ease of Use: Methods like . forEach() make it simple to loop through data.
  • Convenience: It's easier to check for a key or delete entries with Map()
Mar 18, 2024

What does _ map () do? ›

Transforming collections is a frequent necessity in JavaScript, and the Lodash library offers a powerful tool for this: the _. map() method. It creates a new array of values by running each element in a collection through an iteratee function. This article will explore the _.

What's the use of map () operation? ›

The map() operation applies the specified function to each element in the collection and returns a new collection of the transformed elements. Here's an example of using the map() operation to transform a collection of strings to uppercase: List<String> words = Arrays.

What is the main function of map? ›

Maps can show distributions of things over Earth, such as settlement patterns. They can show exact locations of houses and streets in a city neighborhood. Mapmakers, called cartographers, create maps for many different purposes. Vacationers use road maps to plot routes for their trips.

When to use mapping in R? ›

Often, data will include a spatial component, and you will want to map the data either for exploratory data analysis or to present interesting aspects of the data to others. R has a range of capabilities for mapping data.

How do I create a map in R? ›

THE MAPS PACKAGE
  1. Step 1 - Select a Basemap. Creating some basic maps in R can be done through a couple of lines of code. ...
  2. Step 2 - Grab Some Data. ...
  3. Step 3 - Define a Color Scheme. ...
  4. Step 4 - Split the Data into Levels. ...
  5. Step 5 - Draw the Map.

What is the meaning of map R? ›

Measures of Academic Progress-Reading (MAP-R)

What is the map () function used to do? ›

Map in Python is a function that works as an iterator to return a result after applying a function to every item of an iterable (tuple, lists, etc.). It is used when you want to apply a single transformation function to all the iterable elements. The iterable and function are passed as arguments to the map in Python.

Why do we use map () in JavaScript? ›

In JavaScript, map() is a method of the Array object. It creates a new array by calling a function on every element of the original array and storing the results in a new array.

Does map return a new array? ›

map() creates a new array from calling a function for every array element. map() does not execute the function for empty elements. map() does not change the original array.

What does map find function do? ›

map find() function in C++ STL

Parameters: The function accepts one mandatory parameter key, which specifies the key to be searched in the map container. Return Value: The function returns an iterator or a constant iterator which refers to the position where the key is present in the map.

What does map R measure? ›

MAP assessments are used to measure student progress and growth in reading and math. These assessments will help teachers understand your child's areas of strength and weakness and provide appropriate instruction.

Top Articles
Why Do High Net Worth Individuals Avoid Crypto?
20 Best ETFs 10 Years • ETFvest
Star Wars Mongol Heleer
Radikale Landküche am Landgut Schönwalde
Kathleen Hixson Leaked
Lamb Funeral Home Obituaries Columbus Ga
Mountain Dew Bennington Pontoon
Stadium Seats Near Me
Gabriel Kuhn Y Daniel Perry Video
What to Serve with Lasagna (80+ side dishes and wine pairings)
Corpse Bride Soap2Day
Slapstick Sound Effect Crossword
Mlifeinsider Okta
Umn Biology
Planets Visible Tonight Virginia
Tight Tiny Teen Scouts 5
4156303136
Calmspirits Clapper
Burn Ban Map Oklahoma
Midlife Crisis F95Zone
Truck Trader Pennsylvania
Rams vs. Lions highlights: Detroit defeats Los Angeles 26-20 in overtime thriller
Walmart stores in 6 states no longer provide single-use bags at checkout: Which states are next?
Zoe Mintz Adam Duritz
Weepinbell Gen 3 Learnset
UPS Store #5038, The
Forest Biome
Adt Residential Sales Representative Salary
Rqi.1Stop
Yog-Sothoth
Violent Night Showtimes Near Amc Dine-In Menlo Park 12
Sound Of Freedom Showtimes Near Movie Tavern Brookfield Square
Claio Rotisserie Menu
Aes Salt Lake City Showdown
Hwy 57 Nursery Michie Tn
Joann Fabrics Lexington Sc
John Deere 44 Snowblower Parts Manual
Big Boobs Indian Photos
Desales Field Hockey Schedule
Moxfield Deck Builder
How to Destroy Rule 34
Tal 3L Zeus Replacement Lid
Dr. John Mathews Jr., MD – Fairfax, VA | Internal Medicine on Doximity
Rhode Island High School Sports News & Headlines| Providence Journal
Ig Weekend Dow
Weather In Allentown-Bethlehem-Easton Metropolitan Area 10 Days
Fool's Paradise Showtimes Near Roxy Stadium 14
Courses In Touch
Tropical Smoothie Address
Joblink Maine
Minterns German Shepherds
Makemkv Key April 2023
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 5447

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.