More

Plotting US maps with selected locations (longitude and latitude of locations are known) in R?

Plotting US maps with selected locations (longitude and latitude of locations are known) in R?


I've been struggling with the following R plotting of the US map and wonder if any of you have suggestions on how the plot should be done.

Here is what I have tried:

US <- map("state",fill=TRUE, plot=FALSE) US.names <- US$names US.IDs <- sapply(strsplit(US.names,":"),function(x) x[1]) US_poly_sp <- map2SpatialPolygons(US,IDs=US.IDs,proj4string=CRS("+proj=longlat + datum=wgs84")) plot(US_poly_sp,col="white",axes=TRUE)

With the above code, I can add points if I need to. For example, suppose I have a location with lat=35 and lon=-110, then I can simply use the next line since the latitude and longitude of the spatial polygon I created from the object US contains information on the location:

points(lon,lat)

How can I get a plot of the map that is curved, as generated from the following line and also add points which are given in terms of their latitude and longitude?

US <- map("state",proj="albers", par=c(30,40), plot=TRUE)

I know it has something to do with the projection of maps, but the moment I projected the map, the corresponding range of the latitude and longitude (US$range) changes.


The best resource is the ggmap and ggplot2 packages in R. Here is a short paper describing details. http://journal.r-project.org/archive/2013-1/kahle-wickham.pdf

There are also materials from a workshop on visualizing climate data at this site: http://streaming.stat.iastate.edu/~dicook/NCAR/


Instead ofpointsuseSpatialPoints. Then you can reproject layers as you wish usingspTransformfrom thergdalpackage.

library(maps) library(maptools) library(sp) library(rgdal) US <- map("state",fill=TRUE, plot=FALSE) US.names <- US$names US.IDs <- sapply(strsplit(US.names,":"),function(x) x[1]) US_poly_sp <- map2SpatialPolygons(US,IDs=US.IDs,proj4string=CRS("+proj=longlat + datum=wgs84")) #point point_sp <- SpatialPoints(data.frame(x=-110,y=35), proj4string=CRS(proj4string(US_poly_sp))) # new CRS: albers.crs <- CRS("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs") # reproject US_poly_sp.albers <- spTransform(US_poly_sp, CRS=albers.crs) point_sp.albers <- spTransform(point_sp, CRS=albers.crs) plot(US_poly_sp.albers,col="white",axes=TRUE) points(point_sp.albers)


MapMaker: Latitude and Longitude

Lines of latitude and longitude help us navigate and describe the Earth. Explore them with MapMaker, National Geographic's classroom interactive mapping tool.

Geography, Geographic Information Systems (GIS), Human Geography, Physical Geography

Graticule

Where are you on Earth? Explore latitude and longitude with this layer.

Links

Latitude and longitude is a gridded coordinate system across the surface of Earth that allows us to pinpoint the exact location. Latitude marks how far north or south of the Equator (zero degrees) one is while longitude determines how far east or west one is from the prime meridian (zero degrees), today located in Greenwich, London, United Kingdom.

Greenwich has not always been the agreed-upon prime meridian. In the 18th century most European countries chose a location unique to them a built their maps off of that reference point. It was not until 1884, when 22 countries met in Washington, D.C., and voted the Greenwich meridian as the international standard.

Other key points of latitude are the Tropic of Cancer (23°27&rsquo N), Tropic of Capricorn (23°27&rsquo S), the Arctic Circle (66°30&rsquo N), and the Antarctic Circle (66°30&rsquo S). The Tropic of Cancer located in the northern hemisphere is the point on Earth that receives the most direct sunlight around June 21st as the north pole tilts toward the sun. This latitude is mirrored by the Tropic of Capricorn in the southern hemisphere and receives the most direct sunlight around December 21st when the south pole is tilted toward the sun. The Arctic Circle, which surrounds the North Pole, marks the point where the sun does not set around June 21st or rise around December 21st. Likewise, the Antarctic Circle, near the South Pole, is the location where the sun does not set around December 21st or rise around June 21st.

Explore this map to find out the latitude and longitude where you are today.


Три очень простых шага

В большинстве случаев, ваши данные готовы для обработки, просто выберите все данные (Ctrl+A или Cmd+A) в таблице и скопируйте их (Ctrl+C или Cmd+C) в буфер обмена.

После чего выполните такие шаги:

Мы же говорили, что это просто, разве нет? Ниже мы рассмотрим различные форматы координат, поддерживаемых нашей системой. Возможно вам придётся немного отредактировать свою таблицу, но мы способны успешно перенести на карту все эти и многие другие форматы данных.


Sometimes, unknown locations can be prompted because there's a misspelling or another issue. When this happens, you can correct the unknown or ambiguous locations in your data using the Special Values menu. To do this:

  1. In the bottom right corner of the view, click the special values indicator that lists the number of unknown locations in your map. This opens the Special Values menu.
  2. In the Special Values dialog box, select Edit Locations .

Note: If the special values indicator is not visible, you can also select Map > Edit Locations

The Edit Locations dialog lets you clarify unrecognized and ambiguous values to locations in Tableau.

Edit ambiguous locations

Both unrecognized and ambiguous locations can be listed in the Edit Locations dialog box.

You can fix some ambiguous locations by specifying the Country/Region and/or State/Province for each city from a specific field in your data, either by hard-coding a value if your data only spans one state or country, or by telling Tableau which fields to refer to for that information. This option is in the Geographic Roles section of the Edit Locations dialog box. For example, if you have several cities that are ambiguous, you can specify a State/Province to fix them.

If there are ambiguous or unknown locations in the Country/Region or State/Province tabs in the Edit Locations menu, fixing those first may resolve some ambiguous locations in smaller geographic roles, such as cities.

Edit unknown locations

In the Edit Locations dialog box, click on one of the Unrecognized cells to match a known location to your unknown data. When you click on an unrecognized cell, a search box appears. As you begin typing in the search box, Tableau generates a list of possible locations. Select a location from the list.

Alternatively, you can enter latitude and longitude to manually map a value to a point location on the map. To do this, begin typing into the unrecognized cell and select Enter Latitude and Longitude from the drop-down menu.

Note: When you type a latitude and longitude, enter the values in decimal format. For example, Addis Ababa is Latitude: 9.033140, Longitude: 38.750080.

Restrict Locations in the List

By default, all possible locations are listed in the drop-down menu. To restrict the list to locations that have not yet been matched to your data, select the Show only unmatched locations in drop-down list option in the bottom left corner of the Edit Locations dialog box.


Fired when an error occurs when attempting to render the chart.

Map are displayed by Google Maps. Please refer to the Google Maps Terms of Service for more information on data policy.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.


Map Configuration and Styling in Python

How to configure and style base maps for Choropleths and Bubble Maps.

Write, deploy, & scale Dash apps and Python data visualizations on a Kubernetes Dash Enterprise cluster.
Get Pricing | Demo Dash Enterprise | Dash Enterprise Overview

Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

Mapbox Maps vs Geo Maps¶

Plotly supports two different kinds of maps:

  1. Mapbox maps are tile-based maps. If your figure is created with a px.scatter_mapbox , px.line_mapbox , px.choropleth_mapbox or px.density_mapbox function or otherwise contains one or more traces of type go.Scattermapbox , go.Choroplethmapbox or go.Densitymapbox , the layout.mapbox object in your figure contains configuration information for the map itself.
  2. Geo maps are outline-based maps. If your figure is created with a px.scatter_geo , px.line_geo or px.choropleth function or otherwise contains one or more traces of type go.Scattergeo or go.Choropleth , the layout.geo object in your figure contains configuration information for the map itself.

This page documents Geo outline-based maps, and the Mapbox Layers documentation describes how to configure Mapbox tile-based maps.


How to Make Hub and Spoke Maps in Tableau

Hub and spoke maps not only plot locations on a map, but they draw connecting lines between the origin and one or more destinations. This type of map can be used to visualize connecting flight routes, travel schedules, migration patterns – or in the following case – the path between our office and my ten favorite barbecue restaurants!

This type of map has become remarkably easy to create with the introduction of the MakePoint and MakeLine functions available as of Tableau 2019.2. I’ve shared before 3 Ways to Make Magnificent Maps, but Tableau keeps innovating, so I’m adding to the series.

This post will show you how to make hub and spoke maps in Tableau with the MakePoint and MakeLine functions, but I’ll be taking this a step further and sharing: (1) how to use these functions without adding extra rows or columns to your dataset and (2) when not to use these new functions.

How to make hub and spoke maps using Tableau’s MakePoint and MakeLine functions

By the end of this post, you will be able to make a hub and spoke map connecting any origin to one or more destination points.

For this tutorial, I will be using this CSV file containing the addresses of my ten favorite barbecue restaurants and Playfair Data’s office.

Note my dataset contains a column for Latitude and Longitude, so we will be using these coordinates instead of the versions that Tableau automatically generates. If Tableau doesn’t automatically recognize your coordinates as Latitude and Longitude, you can assign them geographic roles by right-clicking on each field, hovering over “Geographic Role”, and choosing Latitude or Longitude.

We will start with the MakePoint function which will, well, ‘make points’, for our origin and destinations. You don’t need this function if you are simply creating a symbol map plotting each location at its respective intersection of Latitude and Longitude. However, making points in this manner can be used with the MakeLine function in the next step to ‘connect the dots’ between locations with a line.

The Syntax for the MakePoint function is MAKEPOINT([Latitude],[Longitude]). We need to use this function in two calculated fields one for our origin and one for our destination(s). As you can see in my dataset, I only have one set of Latitude / Longitude coordinates, so I’ll start with those. This calculated field will eventually make points for my destinations:

Next, we will need a calculated field that creates the point for our origin. Your dataset may have four columns for geographic coordinates (Origin Latitude, Origin Longitude, Destination Latitude, and Destination Longitude), in which case you would use the Origin coordinates with the MakePoint function to create your Origin points and your Destination coordinates with the MakePoint function to create your Destination coordinates.

However, as promised in the post’s introduction, I’m going to show you how to isolate the coordinates for the origin without the need for those two extra columns. To create the origin point, I’m going to use a FIXED level of detail expression to isolate the coordinates for Playfair Data’s office. The formula is:

Note you don’t see the expression, FIXED, in the calculated field. FIXED is the default level of detail expression and when you’re not addressing any specific dimension, you don’t need to include the word. This is a trick I picked up from my friend Carl Allchin at The Information Lab.

In case it’s easier for you to understand what this is doing, this calculation can also be written as:

We are now ready to make our connecting lines using the MakeLine function. The syntax for the MakeLine function is MAKELINE([Start Point],[End Point]). I will make another calculated field and plug in my [Origin Point] and [Destination Points] calculations.

MAKELINE([Origin Point],[Destination Points])

You can also nest the calculations required to create the origin point and destination points, but I find it easier to manage when these are separated into their own calculated fields. If you would prefer to have everything in one calculation, the formula would be:

We’re now ready to make the hub and spoke map! First, place your Longitude measure on the Columns Shelf and Latitude measure on the Rows Shelf.

By default, this creates a symbol map with one circle. That one mark represents the intersection of the average Longitude and average Latitude across the entire data source.

When you are creating a map from fields with geographic roles like we are, ensure you change the mark type from the default, Circle, to Map.

After changing the mark type to Map, simply placing the calculated field created with the MakeLine function to the Detail Marks Card will draw a line between the origin and each destination!

Note you do not always need to use the MakePoint and MakeLine functions to connect locations with a line. The approach outlined in this post is the most efficient way to make a hub and spoke map, but if you are simply wanting to connect points in a sequential order, you are better off changing the mark type to Line and adding a field for point order to the Path Marks Card. For a detailed tutorial on this approach, see How to Make a Sequential Path Map in Tableau.

There are some optional steps if you want to match the hub and spoke map pictured in this post’s introduction including:

– Make a dual-axis map with the second axis containing a symbol map. This technique is used to make the larger circle marks at the end of each ‘spoke’.
– Change the map style to Streets (available as of Tableau 2019.2) by navigating to ‘Maps > Map Layers…’ in the top navigation and changing the option selected in the Style dropdown menu on the Map Styles pane.
– Color the marks by whether they are an origin or destination.
– I did not do this in my example, but you can parameterize the origin by simply replacing the hardcoded location (“Playfair Data” in my example) with a parameter containing allowable values that match each potential origin.

As you can see, Playfair Data is strategically located between my ten favorite barbecue restaurants in Kansas City!


Create a dual-axis map from custom latitude and longitude fields

If your data source contains custom latitude and longitude fields, you can use them instead of the Tableau Latitude (generated) and Longitude (generated) fields to create a dual-axis map. Follow the steps below to learn how.

Open Tableau and connect to a data source with custom latitude and longitude values.

Navigate to a new worksheet.

In the Data pane, right-click the custom latitude field and select Geographic Role > Latitude .

Note that the Latitude geographic role may already be assigned to the field.

In the Data pane, right-click the custom longitude field and select Geographic Role > Longitude .

Note that the Longitude geographic role may already be assigned to the field.

From the Data pane, drag the custom latitude field to the Rows shelf.

From the Data pane, drag the custom longitude field to the Columns shelf.

From the Data pane, under Dimensions, drag a geographic field to Detail on the Marks card.

In this example, the geographic field, Country (Name), is used.

On the Marks card, click the Mark Type drop-down and select Map .

The map updates to a filled map.

On the Rows shelf, Ctrl-click (Command-click on a Mac) and drag the custom latitude field to the right. This copies the field.

A second, identical map is created and the Marks card updates to include three tabs. The middle tab is for the top map, and the bottom tab is for the bottom map.

On the Marks card, click the bottom tab and remove the geographic field by dragging it off.

From the Data pane, drag a new geographic field to Detail on the Marks card.

In this example, Airport (City) is used.

On the Marks card, click Color and select a color for the marks. In this example, the color orange is used.

On the Rows shelf, right-click the custom latitude field on the right and select Dual Axis .

The two maps are now combined.