It is possible to draw interactive linguistic maps using lingtypology
import lingtypology
In this paragraph I will consider some basic features that you can use.
The simplest script that draws a map with Romanian and Ukrainian languages will be:
m = lingtypology.LingMap(('Romanian', 'Ukrainian'))
m.create_map()
Be advised that create_map()
returns a Folium
map. In this notebook it is used because the map may
be displayed this way.
To save your map as html run: m.save('map.html')
To get html as str
run: m.render()
Simply drawing languages on a map is not very interesting. Let's say that we want to mark some morphological features as different colors.
languages = ["Adyghe", "Kabardian", "Polish", "Russian", "Bulgarian"]
features = ["Agglutinative", "Agglutinative", "Inflected", "Inflected", "Analythic"]
m = lingtypology.LingMap(languages)
m.add_features(features)
m.create_map()
As you can see, the map is not centered properly. It can be fixed with passing coordinates to the start_location
attribute. You can change start zoom as well start_zoom
.
Also, you can change colors using the colors
attribute.
m.start_location = (40, 40)
m.start_zoom = 3
m.colors = ("yellowgreen", "red", "blue")
m.create_map()
affs = lingtypology.glottolog.get_affiliations(languages)
m.add_popups(affs)
m.create_map()
You can pass additional parameters to the add_features
method.
If for some reason you do not wish to use colors, you could use shapes.
If you want to add controls, you can do it as well.
m.add_features(features, use_shapes=True, control=True)
m.create_map()
It is possible to add another set of features to strokes of markers.
stroke_features = ['Ergative', 'Ergative', 'Accusative', 'Accusative', 'Accusative']
m = lingtypology.LingMap(languages)
m.add_features(features)
m.add_stroke_features(stroke_features)
m.create_map()
from lingtypology.db_apis import Wals
wals_page = Wals('1a').get_df()
#First initialize LingMap without languages
m = lingtypology.LingMap()
#Add heatmap from the Wals data
m.add_heatmap(wals_page[wals_page._1A == 'Large'].coordinates)
#Let's also add a title to the map
m.title = 'Large Consonant Inventories'
m.create_map()
Let's say we have this list of languages:
balkan = ['Modern Greek', 'Romanian', 'Bulgarian', 'Macedonian', 'Gheg Albanian']
other = ['Ukrainian', 'Turkish', 'Italian']
languages_all = balkan + other
We want the ones from Balkan sprachbund connected with lines.
#Let's get the coordinates that we need to draw a line
coordinates = map(lingtypology.glottolog.get_coordinates, balkan)
m = lingtypology.LingMap(languages_all)
m.add_line(coordinates)
m.start_location = (43, 27)
m.start_zoom = 5
m.create_map()
It is possible to set opacity and width of markers.
m = lingtypology.LingMap(languages)
m.add_features(features, radius=7, opacity=0.9)
m.add_stroke_features(stroke_features, opacity=0.7)
m.create_map()
There are some shortcuts that can allow not to choose start_location
and start_zoom
manually.
m = lingtypology.LingMap([
'Irish', 'Estonian', 'Norwegian', 'Romanian', 'Polish',
'Italian', 'Turkish', 'French', 'English', 'Spanish'
])
m.start_location = 'Central Europe'
m.create_map()
Full list of shortcuts:
m.start_location_mapping
There are two ways to use color gradients. Let's say we have features called "Millions of native speakers".
native_speakers = [0, 1, 5, 24, 44, 62, 78, 78, 378, 442]
m.legend_title = 'Native speakers (mln)'
m.legend_position = 'topright'
The first way is simply pass the features as numeric:
m.add_features(native_speakers, numeric=True)
m.colormap_colors = ('white', 'red')
m.create_map()
Or you can simply set attribute color
to a gradient using gradient
function.
m.add_features(native_speakers)
m.colors = lingtypology.gradient(10, color2='red')
m.create_map()
You can add minicharts to the map using add_minicharts
method.
import pandas
data = pandas.read_csv(
'https://raw.githubusercontent.com/ropensci/lingtypology/master/database_creation/ejective_and_n_consonants.csv',
delimiter=',',
header=0,
)
m = lingtypology.LingMap(data.language)
m.add_minicharts(data.consonants, data.vowels, names=('consonants', 'vowels'))
m.create_map()
It is possible to customize them using colors
, size
, startangle
and labels
parameters.
m = lingtypology.LingMap(data.language)
m.add_minicharts(
data.consonants, data.vowels,
names = ('consonants', 'vowels'),
colors = ('#4363d8', '#d8b843'), #default: default colors of LingMap
size = 0.8, #default: 0.6
startangle = 45, #default: 90
labels = True #default: False
)
m.create_map()
You can also use bar charts.
m = lingtypology.LingMap(data.language)
m.add_minicharts(
data.consonants, data.vowels,
names = ('consonants', 'vowels'),
typ = 'bar',
colors = ('#4363d8', '#d8b843'),
size = 0.4
)
m.create_map()
import pandas
circassian = pandas.read_csv(
'https://raw.githubusercontent.com/ropensci/lingtypology/master/database_creation/circassian.csv',
delimiter=',',
header=0,
)
circassian.head()
coordinates = zip(list(circassian.latitude), list(circassian.longitude))
dialects = circassian.dialect
languages = circassian.language
popups = circassian.village
#Creating LingMap object
m = lingtypology.LingMap(languages)
#Setting up start location
m.start_location = (44.21, 42.32)
#Setting up start zoom
m.start_zoom = 7
#Inner features < dialect
m.add_features(dialects, opacity=0.7)
#Outer features < language
m.add_stroke_features(languages, opacity=0.8)
#Popups < village
m.add_popups(popups)
#Tooltips < language
m.add_tooltips(languages)
#Custom coordinates (override the ones from Glottolog)
m.add_custom_coordinates(coordinates)
#Inner legend title and position
m.legend_title = 'Dialects'
m.legend_position = 'bottomright'
#Outer legend title and position
m.stroke_legend_title = 'Languages'
m.stroke_legend_position = 'topright'
m.create_map()
If you are used to the R package, you may find this way to program the second example more appealing.
However, it is not recommended because most of customization is impossible.
coordinates = zip(list(circassian.latitude), list(circassian.longitude))
dialects = circassian.dialect
languages = circassian.language
popups = circassian.village
lingtypology.map_feature(
languages,
custom_coordinates = coordinates,
features = dialects,
stroke_features = languages,
popups = popups,
tooltips = languages,
legend_title = 'Dialects',
legend_position = 'bottomright',
stroke_legend_title = 'Languages',
stroke_legend_position = 'topright',
start_zoom = 7,
start_location = (44.21, 42.32),
save_html = 'circassian.html',
)
data = pandas.read_csv(
'https://raw.githubusercontent.com/ropensci/lingtypology/master/database_creation/ejective_and_n_consonants.csv',
delimiter=',',
header=0,
)
m = lingtypology.LingMap(data.language)
m.legend_title = 'Amount of consonants'
m.add_tooltips(data.consonants)
#If numeric is True, it will look like this
m.add_features(data.consonants, numeric=True)
m.create_map()