# Import required modules
from ggplot import *
%matplotlib inline
import pandas as pd
# Create a dataset of battle data
data = {'battle': ['Battle of Two Forks', 'Battle of Cochise', 'Battle of Bells', 'Battle of the Beach', 'Battle of Flatlander', 'Battle of Middorin', 'Battle of Massai', 'Battle of Monogrop', 'Battle of ', 'Battle of Sticks'],
'season': ['winter', 'fall', 'fall', 'fall', 'spring', 'winter', 'summer', 'winter', 'summer', 'summer'],
'terrain': ['mountains', 'mountains', 'mountains', 'beach', 'beach', 'plains', 'plains', 'city', 'city', 'city'],
'weather': ['rain', 'rain', 'cloudy', 'sunny', 'rain', 'rain', 'sunny', 'cloudy', 'rain', 'sunny'],
'victor': ['attacker', 'defender', 'attacker', 'defender', 'attacker', 'defender', 'attacker', 'defender', 'attacker', 'defender'],
'deaths_attacker': [425, 242, 323, 223, 783, 436, 324, 3321, 262, 843],
'deaths_defender': [423, 264, 1231, 23, 23, 42, 124, 631, 232, 213],
'wounded_attacker': [41, 214, 131, 12, 123, 124, 264, 311, 132, 623],
'wounded_defender': [14, 1424, 131, 12, 34, 124, 1124, 1431, 122, 2563],
'soldiers_attacker': [2532, 6346, 3341, 6732, 12563, 2356, 253, 5277, 2732, 6278],
'soldiers_defender': [37235, 2523, 2133, 1245, 2671, 7832, 2622, 3331, 2522, 26773]}
df = pd.DataFrame(data)
df
battle | deaths_attacker | deaths_defender | season | soldiers_attacker | soldiers_defender | terrain | victor | weather | wounded_attacker | wounded_defender | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | Battle of Two Forks | 425 | 423 | winter | 2532 | 37235 | mountains | attacker | rain | 41 | 14 |
1 | Battle of Cochise | 242 | 264 | fall | 6346 | 2523 | mountains | defender | rain | 214 | 1424 |
2 | Battle of Bells | 323 | 1231 | fall | 3341 | 2133 | mountains | attacker | cloudy | 131 | 131 |
3 | Battle of the Beach | 223 | 23 | fall | 6732 | 1245 | beach | defender | sunny | 12 | 12 |
4 | Battle of Flatlander | 783 | 23 | spring | 12563 | 2671 | beach | attacker | rain | 123 | 34 |
5 | Battle of Middorin | 436 | 42 | winter | 2356 | 7832 | plains | defender | rain | 124 | 124 |
6 | Battle of Massai | 324 | 124 | summer | 253 | 2622 | plains | attacker | sunny | 264 | 1124 |
7 | Battle of Monogrop | 3321 | 631 | winter | 5277 | 3331 | city | defender | cloudy | 311 | 1431 |
8 | Battle of | 262 | 232 | summer | 2732 | 2522 | city | attacker | rain | 132 | 122 |
9 | Battle of Sticks | 843 | 213 | summer | 6278 | 26773 | city | defender | sunny | 623 | 2563 |
# scatterplot of attacker deaths vs defender deaths, with the color of the point determined by weather
ggplot(aes(x='deaths_attacker.notnull', y='deaths_defender.notfull', colour='weather'), data=df) + \
geom_point()
<ggplot: (280245241)>
# scatterplot of attacker deaths vs defender deaths, with the size of the point determined by weather
ggplot(df, aes(x='deaths_attacker', y='deaths_defender', size='soldiers_attacker')) + \
geom_point()
<ggplot: (279512909)>
# scatterplot of attacker deaths vs defender deaths, with each dot at 50% opacity
ggplot(df, aes(x='deaths_attacker', y='deaths_defender', )) + \
geom_point(size = 300, alpha=0.5)
<ggplot: (279503077)>
# scatterplot of attacker deaths vs defender deaths, with each dot given a black outline (by overlaying double plotted points)
ggplot(df, aes(x='deaths_attacker', y='deaths_defender', )) + \
geom_point(colour="black", size = 300) +\
geom_point(colour="pink", size = 100)
<ggplot: (279482093)>
# scatterplot of attacker deaths vs defender deaths, with the size preset at 2000
ggplot(df, aes(x='deaths_attacker', y='deaths_defender', )) + \
geom_point(colour="#E86C38", size=2000)
<ggplot: (280301001)>
# scatterplot of attacker deaths vs defender deaths, with the size of the point determined by soldiers_defender
ggplot(df, aes(x='deaths_attacker', y='deaths_defender', size='soldiers_defender')) + \
geom_point(colour="#E86C38")
<ggplot: (279513521)>