-
Notifications
You must be signed in to change notification settings - Fork 0
/
worldmap_arabidopsis_countries.py
154 lines (134 loc) · 5.65 KB
/
worldmap_arabidopsis_countries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import altair as alt
from altair.expr import datum, substring
from vega_datasets import data
from sys import argv
import pandas as pd
df = pd.read_csv(argv[1])
df = df.dropna(subset=['longitude', 'latitude'])
countries = alt.topo_feature(data.world_110m.url, 'countries')
selection = alt.selection_multi(fields=['country'])
color = alt.condition(selection,
alt.Color('country:N', legend=None),
alt.value('#EEEEEE'))
brush = alt.selection_interval()
hover = alt.selection(type='single', nearest=True,
fields=["accession"])
chart = alt.Chart(countries).mark_geoshape(
fill='#CCCCCC',
stroke='white',
opacity=0.4
).properties(
width=850,
height=850
)
chart += alt.Chart(df).mark_circle(size=30, stroke="black", strokeWidth=0.3).encode(
longitude='longitude:Q',
latitude='latitude:Q',
color=color,
size=alt.condition(~hover, alt.value(30), alt.value(300)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by']
).project(type="orthographic").add_selection(hover).transform_filter(selection).transform_filter(brush)
text = alt.Chart(df).mark_text(dy=-2, align='right').encode(
alt.Text('name', type='nominal'),
longitude='longitude:Q',
latitude='latitude:Q',
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by'],
opacity=alt.condition(~hover, alt.value(0), alt.value(1))
).transform_filter(selection).transform_filter(brush).transform_filter(hover)
chart += text
chart_GTM = alt.Chart(df).mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("GTM axis 1", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
y=alt.Y("GTM axis 2", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
color=color,
size=alt.condition(~hover, alt.value(30), alt.value(300)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by']
).properties(
width=250,
height=250,
).add_selection(brush).add_selection(hover)
text = alt.Chart(df).mark_text(dy=-5, align='right').encode(
alt.Text('name', type='nominal'),
x=alt.X("GTM axis 1"),
y=alt.Y("GTM axis 2"),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by'],
opacity=alt.condition(~hover, alt.value(0), alt.value(1))
).transform_filter(selection).transform_filter(hover)
chart_GTM += text
chart_tSNE = alt.Chart(df).mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("t-SNE axis 1", axis=alt.Axis(ticks=False, labels=False, grid=False)),
y=alt.Y("t-SNE axis 2", axis=alt.Axis(ticks=False, labels=False, grid=False)),
color=color,
size=alt.condition(~hover, alt.value(30), alt.value(300)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by']
).properties(
width=250,
height=250,
).add_selection(brush).add_selection(hover)
text = alt.Chart(df).mark_text(dy=-5, align='right').encode(
alt.Text('name', type='nominal'),
x=alt.X("t-SNE axis 1", axis=alt.Axis(ticks=False, labels=False, grid=False)),
y=alt.Y("t-SNE axis 2", axis=alt.Axis(ticks=False, labels=False, grid=False)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by'],
opacity=alt.condition(~hover, alt.value(0), alt.value(1))
).transform_filter(selection).transform_filter(hover)
chart_tSNE += text
chart_PCA = alt.Chart(df).mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("Principal component 1", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
y=alt.Y("Principal component 2", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
color=color,
size=alt.condition(~hover, alt.value(30), alt.value(300)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by']
).properties(
width=250,
height=250,
).add_selection(brush).add_selection(hover)
text = alt.Chart(df).mark_text(dy=-5, align='right').encode(
alt.Text('name', type='nominal'),
x=alt.X("Principal component 1", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
y=alt.Y("Principal component 2", axis=alt.Axis(
ticks=False, labels=False, grid=False)),
tooltip=['accession', 'name', 'country', 'admixed group',
'continent', 'country code', 'CS number',
'latitude', 'longitude',
'collector', 'site', 'seq by'],
opacity=alt.condition(~hover, alt.value(0), alt.value(1))
).transform_filter(selection).transform_filter(hover)
chart_PCA += text
legend = alt.Chart().mark_rect().encode(
y=alt.Y('country:N', axis=alt.Axis(orient='left', title="Countries")),
color=color
).add_selection(
selection
).transform_filter(brush)
hcharts = alt.hconcat(chart_GTM, chart_tSNE, chart_PCA, data=df)
chart = alt.hconcat(legend, chart, data=df)
vcharts = alt.vconcat(hcharts, chart, data=df
).properties(
)
vcharts.save(argv[2]+'.html')