Building a choropleth map of Italy using MapIT

Source: Internet
Author: User
Tags choropleth map

In the R environment, different packages to draw maps is available. I lost the count by now; Surely, Spand Ggmap deserve consideration. Despite the great availability of R functions dedicated to this topic, in the past, when I needed to draw a very basic map of Italy with regions marked with different colours (namely a choropleth map), I had a bit of difficulties.

My expectation is that building a choropleth map of Italy using R is a extremely trivial procedure, but my experience WA S different. In fact, if the aim was to represent a maps of the States, the most part of the available functions was very easy-to-use. However, to draw a map of Italy, the procedures become a bit complicated if compared to the banality of the chart (a good Tutorial-in Italian–can is found here).

I wasn ' t the only one R user has this problem. Some time ago, in the community [email protected], Lorenzo di Blasio proposed a good solution using GGPLOT2. Summarizing the code proposed by Lorenzo, I assembled a first function capable to create a map in a easy and fast. Finally, Nicola Sturaro of Milanor group have strongly improved and completed the code and created a new package: MapIT .

Currently, the package MapIT is located to a repository on GitHub. The order to install the package Devtools:

1 Library (Devtools) 2 Install_github ("quantide/mapit")

In my first use of MapIT, I had to map the number of wineries taken into account in a regarding Italian wine eval Uations. I need to visualize, the number of wineries whose wines were reviewed. In the following code, there is the data; For each Italian region (first column), the number of wineries (second column) is reported.

1Wine <-Data.frame (2Region = C ("Abruzzo","Basilicata","Calabria","Campania",3                "Emilia-Romagna","Friuli-Venezia Giulia","Lazio",4                "Liguria","Lombardia","Marche","Molise","Piemonte",5                "Puglia","Sardegna","Sicilia","Toscana",6                "Trentino-alto Adige","Umbria","Valle d\ ' Aosta","Veneto"),7Wineries = C (22,8,9,35,24,74,19,8,41,29,5,191,22,14,40,173,57,29,6,92)8)

The names of regions can is written both in lowercase and uppercase. Spaces and other non-alphabetical characters would be ignored. So, you can write indifferently: ' Trentino-alto Adige ', ' Trentino Alto Adige ' or ' Trentinoaltoadige '. For regions with bilingual denomination, only the Italian wording is accepted.
to build the map, the package MapIT make available the namesake function  MapIT () . The first argument to pass to the function are the numeric variable (wineries) and the second one is the variable Specifyin G The Italian region. A third argument can be used to specify the data frame from which extract the variables.
Further, there is some additional arguments useful to modify the graphic style. In the following example I used Guide.label, which specifies the title label for the legend.

1 Library (MapIT) 2 MapIT (wineries, Region, Data=wine, guide.label="numberof\nwineries")

Easy, right? It is enough to load the package and launch a brief row of code!
The chart can be customized in several ways. The main argument allowing to alter the graphic details are graphpar, consisting in a long list of arguments (for details, See the Help function).
One of the first things we want to do, surely'll be alter the colours. To alter the colours, your must specify, in the Graphpar list, the colours for the minimum value (low) and for the maximum Value (High):

1 GP <-list (low="#fff0f0", high="red3")

For convenience I saved the list into the object GP. Note that colours can is specified using both the hexadecimal code and the R keywords for colours.

1 MapIT (wineries, region, Data=wine,2       guide.label="numberof\ Nwineries",  GRAPHPAR=GP)

You can play with colours to find your preferred arrangement. To identify the hexadecimal code for colours, a fast solution are to use a Web applications as RGB color picker.
The low and high values of graphpar can is used to convert the chart in black and white. In the the the the chart a bit more pleasant, it's possible use the themes of ggplot2. In the examples below, the first map (left panel) is built using the theme THEME_BW, while the second map (right panel) W As built using the theme Theme_grey.

1 Library (GGPLOT2)2  3 #Theme:black and White4GP <-List (low=" White", high="Gray20", theme=THEME_BW ())5MapIT (wineries, region, data=Wine,6Guide.label="Number of\nwineries", graphpar=GP)7  8 #Theme:grey9GP <-List (low=" White", high="Gray20", theme=Theme_grey ())TenMapIT (wineries, region, data=Wine, OneGuide.label="Number of\nwineries", GRAPHPAR=GP)

Still there is different features to implement and, in the future, some things can is changed. If you have some ideas to improve mapIT, or you found a malfunctioning, you can open an issue on GitHub.

Transferred from: http://www.milanor.net/blog/?p=1605

Building a choropleth map of Italy using MapIT (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.