# Part 2: Connecting House Sales Between Years¶

### Combine multiple sales of the same house in a year into one taking the mean of prices¶

Originally we simply sorted by the date of transfer and took the first occurance of the house in each year. Instead, we now group all sales of the same house in each year into one row and take the mean adjusted price of the sales.

In [18]:
# Old method of simply taking first occurence
#data2 = data.sort_values(by=['Date of Transfer'])

# New method of taking the mean of all sales of the same house in that year

In [19]:
data2.head()

Out[19]:
0 AL1 1AJ 10 ORIENT CLOSE T 1997 Rest of UK 157000.0 270040.0
1 AL1 1AJ 11 ORIENT CLOSE S 1997 Rest of UK 156000.0 268320.0
2 AL1 1AJ 11 ORIENT CLOSE S 2000 Rest of UK 265000.0 421350.0
3 AL1 1AJ 12 ORIENT CLOSE S 1997 Rest of UK 139995.0 240791.4
4 AL1 1AJ 13 ORIENT CLOSE S 1997 Rest of UK 119995.0 206391.4
In [20]:
# Seperate each year into its own table

data1995 = data2.loc[data2['Year']==1995]
data1996 = data2.loc[data2['Year']==1996]
data1997 = data2.loc[data2['Year']==1997]
data1998 = data2.loc[data2['Year']==1998]
data1999 = data2.loc[data2['Year']==1999]
data2000 = data2.loc[data2['Year']==2000]
data2001 = data2.loc[data2['Year']==2001]
data2002 = data2.loc[data2['Year']==2002]
data2003 = data2.loc[data2['Year']==2003]
data2004 = data2.loc[data2['Year']==2004]
data2005 = data2.loc[data2['Year']==2005]
data2006 = data2.loc[data2['Year']==2006]
data2007 = data2.loc[data2['Year']==2007]
data2008 = data2.loc[data2['Year']==2008]
data2009 = data2.loc[data2['Year']==2009]
data2010 = data2.loc[data2['Year']==2010]
data2011 = data2.loc[data2['Year']==2011]
data2012 = data2.loc[data2['Year']==2012]
data2013 = data2.loc[data2['Year']==2013]
data2014 = data2.loc[data2['Year']==2014]
data2015 = data2.loc[data2['Year']==2015]
data2016 = data2.loc[data2['Year']==2016]
data2017 = data2.loc[data2['Year']==2017]

In [21]:
data1995.head()

Out[21]:
192 AL1 1BH ALBENY GATE BELMONT HILL F 1995 Rest of UK 64500.0 118035.0
215 AL1 1BH ALBENY GATE BELMONT HILL T 1995 Rest of UK 55000.0 100650.0
216 AL1 1BX 40 HOLYWELL HILL T 1995 Rest of UK 412000.0 753960.0
230 AL1 1BX 66 HOLYWELL HILL T 1995 Rest of UK 161500.0 295545.0
260 AL1 1DG 7 PONDWICKS CLOSE D 1995 Rest of UK 315000.0 576450.0

#### Inner join a year based on the address features to match the same house between years if it appears in both years.¶

In [22]:
data_1995_2017 = data1995.merge(data2017, on = ['Post Code', 'Address 1','Address 3',
'Property Type'], how = 'inner')


Out[22]:
0 1995 118035.0 2017 300500.0 Rest of UK
1 1995 177815.0 2017 405000.0 Rest of UK
2 1995 158752.5 2017 600000.0 Rest of UK
3 1995 151890.0 2017 455000.0 Rest of UK
4 1995 101565.0 2017 320000.0 Rest of UK

#### Unfortunately, the plot creates so many points that it is difficult to load correctly and is extremely cluttered. We therefore need to consider more practical ways to visualise with the high density of houses in the lower price brackets.¶

In [23]:
x1 = data_1995_2017['AdjustedPrice_x'].loc[data_1995_2017['LondonCheck_x']=="GREATER LONDON"]
slope1, intercept1, r_value1, p_value1, std_err1 = stats.linregress(x1,y1)
line1 = slope1*x1+intercept1

slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(x2,y2)
line2 = slope2*x2+intercept2

# The number of rows in greater london is .. percent of the number of rows in the rest of the UK data
1-((len(x2)-len(x1))/len(x2))

Out[23]:
0.1941564852523756
In [24]:
trace0 = go.Scatter(
name = 'London',
mode = 'markers',
marker = dict(
size = 10,
color = 'rgba(152, 0, 0, .8)',
line = dict(
width = 2,
color = 'rgb(0, 0, 0)'
)
)
)

trace1 = go.Scatter(
name = 'Rest of UK',
mode = 'markers',
marker = dict(
size = 10,
color = 'rgba(255, 182, 193, .9)',
line = dict(
width = 2,
color = 'rgb(0, 0, 0)'
)
)
)

trace2 = go.Scatter(
x=x1,
y=line1,
mode='lines',
marker=go.Marker(color='rgba(152, 0, 0, .8)'),
name='London Fit'
)

trace3 = go.Scatter(
x=x2,
y=line2,
mode='lines',
marker=go.Marker(color='rgba(255, 182, 193, .9)'),
name='Rest of UK Fit'
)

datascatter = [trace0, trace1, trace2, trace3]

layout_scatter = dict(title = 'Comparison of the Adjusted Price of the Same House in 1995 Sold Again in 2017 <br> Seperated by whether in London or Rest of UK',
yaxis = dict(title = 'Price 1995 (£)',zeroline = False, range = [0,10000000]),
xaxis = dict(title = 'Price 2017 (£)',zeroline = False, range = [0,10000000])
)

fig = dict(data=datascatter, layout=layout_scatter)

#iplot(fig, filename='1995 to 2017', validate = False)


### Handling Large Amounts of Data in One Plot¶

Instead of reducing the data further, we can apply R’s Hexbins which group the points and then shades the hexagons based on the amount in each to illustrate the denser areas.

In [25]:
%load_ext rpy2.ipython

In [26]:
%%R -i x1,y1 -w 5 -h 5 --units in -r 200
library(hexbin)
hbin <- hexbin(x1,y1,xbins = 40)
plot(hbin)


#### GG plot also has a Hexbin visual that allows us more customisation options and can improve our aesthetics for analysis¶

In [27]:
%%R -i x1,y1,x2,y2,line1,line2  -w 5 -h 4 --units in -r 200
#install.packages("plotly")
library(ggplot2)
library(plotly)
df <- data.frame(x1,y1, line1)
df2 <- data.frame(x2,y2,line2)
hbin2 <- ggplot() +
stat_binhex(data=df,aes(x=x1,y=y1, alpha=log10(..count..)), fill="#A833FF", line = "#fffff", bins = 75) +
stat_binhex(data=df2,aes(x=x2,y=y2, alpha=log10(..count..)), fill="#33FFA6", bins = 75) +
guides(fill = FALSE, alpha=FALSE) +
ggtitle('Comparison of the Adjusted Price of the Same House in 1995 Sold Again in 2017 \n Seperated by whether in London or Rest of UK')+
scale_x_continuous(name="Price 1995 (£)", labels = scales::comma) +
scale_y_continuous(name="Price 2017 (£)", labels = scales::comma)+
theme(panel.background = element_rect(fill='black' ,colour='#ababab'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
title = element_text(size=7)) +
geom_line(color = '#ee77ee', data = df, aes(x=x1,y=line1)) +
geom_line(color = '#36e3e3', data = df2, aes(x=x2,y=line2)) +
annotate(geom = 'text', label = 'London', color = '#A833FF', x=2000000, y = 7500000)+
annotate(geom = 'text', label = 'Rest of UK', color = '#33FFA6', x=3500000, y = 8000000)

plot(hbin2)

In [28]:
%%R
# Or we can use Plot.ly to make this a bit clearer
hbin3 <-(ggplotly(hbin2))
#hbin3


### Create dictionary of data tables connecting each year to all possible future years¶

In [29]:
dfs = [data1995,data1996,data1997,data1998,data1999,data2000,data2001,data2002,data2003,data2004,data2005,data2006,
data2007,data2008,data2009,data2010,data2011,data2012,data2013,data2014,data2015,data2016,data2017]

d={}
for i in range(0,22):
for j in range(1,23):
if j <= i:
continue
else:
d["data_" +str(i+1995) +"_"+str(j+1995)] = dfs[i].merge(dfs[j],  on = ['Post Code', 'Address 1','Address 3','Property Type'], how = 'inner')

In [30]:
d["data_2016_2017"].head()

Out[30]:
0 2016 300900.000 2017 300500.0 Rest of UK
1 2016 460020.000 2017 470000.0 Rest of UK
2 2016 422002.560 2017 385000.0 Rest of UK
3 2016 277100.000 2017 295000.0 Rest of UK
4 2016 384954.375 2017 435600.0 Rest of UK
In [31]:
HouseCountComparison = pd.DataFrame([])
for i in range(1995,2017):
for j in range(1996,2018):
if j <= i:
continue
else:
#print(str(i) + "-" +str(j) +": " + str(len(d["data_"+str(i)+"_"+str(j)])))
count = len(d["data_"+str(i)+"_"+str(j)])
HouseCountComparison2 = pd.DataFrame([[i,j,count]])
HouseCountComparison = HouseCountComparison.append(HouseCountComparison2)

HouseCountComparison.columns = ['Year1', 'Year2', 'Count']

In [32]:
HouseCountComparison.head()

Out[32]:
Year1 Year2 Count
0 1995 1996 41411
0 1995 1997 59742
0 1995 1998 70056
0 1995 1999 81331
0 1995 2000 75023
In [33]:
HouseCountComparisonMatrix = HouseCountComparison.pivot("Year1", "Year2")
HouseCountComparisonMatrix

Out[33]:
Count
Year2 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
Year1
1995 41411.0 59742.0 70056.0 81331.0 75023.0 81053.0 83171.0 72617.0 68735.0 58641.0 31323.0 30049.0 32854.0 31944.0 30721.0 35737.0 41852.0 40432.0 39510.0 38705.0
1996 NaN 55778.0 71386.0 92036.0 88154.0 97713.0 100047.0 86866.0 83032.0 70706.0 36892.0 36445.0 39939.0 38260.0 36780.0 43111.0 50163.0 48507.0 47024.0 45863.0
1997 NaN NaN 64354.0 95593.0 100646.0 112797.0 117502.0 101954.0 96957.0 82096.0 42906.0 42022.0 45872.0 44137.0 42793.0 49669.0 58293.0 55985.0 54437.0 52990.0
1998 NaN NaN NaN 71381.0 90138.0 109241.0 117177.0 102661.0 97799.0 82544.0 42351.0 41429.0 45152.0 43112.0 41648.0 48724.0 57188.0 54632.0 53533.0 52050.0
1999 NaN NaN NaN NaN 77513.0 110513.0 129669.0 116165.0 112524.0 94211.0 48219.0 46636.0 52056.0 49159.0 46910.0 55079.0 64674.0 62143.0 60735.0 59063.0
2000 NaN NaN NaN NaN NaN 81739.0 117606.0 114519.0 111228.0 93367.0 47798.0 45145.0 49780.0 47464.0 45384.0 52924.0 63254.0 60362.0 59075.0 57444.0
2001 NaN NaN NaN NaN NaN NaN 97005.0 118047.0 121367.0 104986.0 53218.0 50551.0 55410.0 52310.0 49955.0 58681.0 69116.0 66838.0 65614.0 63586.0
2002 NaN NaN NaN NaN NaN NaN NaN 101658.0 126434.0 114171.0 59158.0 54441.0 59928.0 56349.0 54135.0 63868.0 75952.0 73323.0 72276.0 69640.0
2003 NaN NaN NaN NaN NaN NaN NaN NaN 94401.0 99209.0 56542.0 50567.0 56048.0 52551.0 50108.0 59274.0 71001.0 68469.0 68089.0 66409.0
2004 NaN NaN NaN NaN NaN NaN NaN NaN NaN 80681.0 57412.0 50900.0 57047.0 53480.0 51506.0 61045.0 74183.0 71310.0 70105.0 68200.0
2005 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 49477.0 44848.0 51345.0 49290.0 46746.0 55899.0 67224.0 65194.0 64471.0 62356.0
2006 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 51640.0 49068.0 58801.0 57874.0 56827.0 68036.0 83082.0 79954.0 79391.0 77982.0
2007 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 42596.0 39735.0 49530.0 50495.0 52028.0 64747.0 81648.0 79232.0 79283.0 77544.0
2008 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 24754.0 27681.0 28895.0 29766.0 37198.0 45380.0 44464.0 44157.0 42814.0
2009 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 26807.0 28439.0 30560.0 38600.0 45038.0 43930.0 43085.0 41503.0
2010 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 27622.0 30065.0 39477.0 48695.0 48294.0 47474.0 45908.0
2011 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 27123.0 34896.0 45450.0 47312.0 48154.0 46467.0
2012 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 30836.0 41424.0 46911.0 49421.0 49042.0
2013 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 40829.0 48750.0 54953.0 56769.0
2014 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 48980.0 58367.0 63745.0
2015 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 50229.0 57077.0
2016 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 48427.0

22 rows × 22 columns

In [34]:
with sns.axes_style("white"):
ax = sns.heatmap(HouseCountComparisonMatrix, linewidth=0.2, cmap = "BuPu")
ax.set_title('Number of times the same house was sold on consecutive years')
ax.set_ylabel('First Year')
ax.set_xlabel('Second Year')
plt.show()


### Create and Save a plot for each year comprison¶

In [35]:
for i in range(1995,2017):
for j in range(1996,2018):
if j <= i:
continue
else:
dataY2YforPlot = (d["data_"+str(i)+"_"+str(j)])

In [36]:
for i in range(1995,2017):
for j in range(1996,2018):
if j <= i:
continue
else:
#"data_"+str(i)+"_"+str(j) + " = " + "d["  + " 'data_" + str(i) + "_" + str(j) + "']"
print("data_"+str(i)+"_"+str(j)+",")


data_1995_1996,
data_1995_1997,
data_1995_1998,
data_1995_1999,
data_1995_2000,
data_1995_2001,
data_1995_2002,
data_1995_2003,
data_1995_2004,
data_1995_2005,
data_1995_2006,
data_1995_2007,
data_1995_2008,
data_1995_2009,
data_1995_2010,
data_1995_2011,
data_1995_2012,
data_1995_2013,
data_1995_2014,
data_1995_2015,
data_1995_2016,
data_1995_2017,
data_1996_1997,
data_1996_1998,
data_1996_1999,
data_1996_2000,
data_1996_2001,
data_1996_2002,
data_1996_2003,
data_1996_2004,
data_1996_2005,
data_1996_2006,
data_1996_2007,
data_1996_2008,
data_1996_2009,
data_1996_2010,
data_1996_2011,
data_1996_2012,
data_1996_2013,
data_1996_2014,
data_1996_2015,
data_1996_2016,
data_1996_2017,
data_1997_1998,
data_1997_1999,
data_1997_2000,
data_1997_2001,
data_1997_2002,
data_1997_2003,
data_1997_2004,
data_1997_2005,
data_1997_2006,
data_1997_2007,
data_1997_2008,
data_1997_2009,
data_1997_2010,
data_1997_2011,
data_1997_2012,
data_1997_2013,
data_1997_2014,
data_1997_2015,
data_1997_2016,
data_1997_2017,
data_1998_1999,
data_1998_2000,
data_1998_2001,
data_1998_2002,
data_1998_2003,
data_1998_2004,
data_1998_2005,
data_1998_2006,
data_1998_2007,
data_1998_2008,
data_1998_2009,
data_1998_2010,
data_1998_2011,
data_1998_2012,
data_1998_2013,
data_1998_2014,
data_1998_2015,
data_1998_2016,
data_1998_2017,
data_1999_2000,
data_1999_2001,
data_1999_2002,
data_1999_2003,
data_1999_2004,
data_1999_2005,
data_1999_2006,
data_1999_2007,
data_1999_2008,
data_1999_2009,
data_1999_2010,
data_1999_2011,
data_1999_2012,
data_1999_2013,
data_1999_2014,
data_1999_2015,
data_1999_2016,
data_1999_2017,
data_2000_2001,
data_2000_2002,
data_2000_2003,
data_2000_2004,
data_2000_2005,
data_2000_2006,
data_2000_2007,
data_2000_2008,
data_2000_2009,
data_2000_2010,
data_2000_2011,
data_2000_2012,
data_2000_2013,
data_2000_2014,
data_2000_2015,
data_2000_2016,
data_2000_2017,
data_2001_2002,
data_2001_2003,
data_2001_2004,
data_2001_2005,
data_2001_2006,
data_2001_2007,
data_2001_2008,
data_2001_2009,
data_2001_2010,
data_2001_2011,
data_2001_2012,
data_2001_2013,
data_2001_2014,
data_2001_2015,
data_2001_2016,
data_2001_2017,
data_2002_2003,
data_2002_2004,
data_2002_2005,
data_2002_2006,
data_2002_2007,
data_2002_2008,
data_2002_2009,
data_2002_2010,
data_2002_2011,
data_2002_2012,
data_2002_2013,
data_2002_2014,
data_2002_2015,
data_2002_2016,
data_2002_2017,
data_2003_2004,
data_2003_2005,
data_2003_2006,
data_2003_2007,
data_2003_2008,
data_2003_2009,
data_2003_2010,
data_2003_2011,
data_2003_2012,
data_2003_2013,
data_2003_2014,
data_2003_2015,
data_2003_2016,
data_2003_2017,
data_2004_2005,
data_2004_2006,
data_2004_2007,
data_2004_2008,
data_2004_2009,
data_2004_2010,
data_2004_2011,
data_2004_2012,
data_2004_2013,
data_2004_2014,
data_2004_2015,
data_2004_2016,
data_2004_2017,
data_2005_2006,
data_2005_2007,
data_2005_2008,
data_2005_2009,
data_2005_2010,
data_2005_2011,
data_2005_2012,
data_2005_2013,
data_2005_2014,
data_2005_2015,
data_2005_2016,
data_2005_2017,
data_2006_2007,
data_2006_2008,
data_2006_2009,
data_2006_2010,
data_2006_2011,
data_2006_2012,
data_2006_2013,
data_2006_2014,
data_2006_2015,
data_2006_2016,
data_2006_2017,
data_2007_2008,
data_2007_2009,
data_2007_2010,
data_2007_2011,
data_2007_2012,
data_2007_2013,
data_2007_2014,
data_2007_2015,
data_2007_2016,
data_2007_2017,
data_2008_2009,
data_2008_2010,
data_2008_2011,
data_2008_2012,
data_2008_2013,
data_2008_2014,
data_2008_2015,
data_2008_2016,
data_2008_2017,
data_2009_2010,
data_2009_2011,
data_2009_2012,
data_2009_2013,
data_2009_2014,
data_2009_2015,
data_2009_2016,
data_2009_2017,
data_2010_2011,
data_2010_2012,
data_2010_2013,
data_2010_2014,
data_2010_2015,
data_2010_2016,
data_2010_2017,
data_2011_2012,
data_2011_2013,
data_2011_2014,
data_2011_2015,
data_2011_2016,
data_2011_2017,
data_2012_2013,
data_2012_2014,
data_2012_2015,
data_2012_2016,
data_2012_2017,
data_2013_2014,
data_2013_2015,
data_2013_2016,
data_2013_2017,
data_2014_2015,
data_2014_2016,
data_2014_2017,
data_2015_2016,
data_2015_2017,
data_2016_2017,

In [37]:
data_1995_1996 = d[ 'data_1995_1996']
data_1995_1997 = d[ 'data_1995_1997']
data_1995_1998 = d[ 'data_1995_1998']
data_1995_1999 = d[ 'data_1995_1999']
data_1995_2000 = d[ 'data_1995_2000']
data_1995_2001 = d[ 'data_1995_2001']
data_1995_2002 = d[ 'data_1995_2002']
data_1995_2003 = d[ 'data_1995_2003']
data_1995_2004 = d[ 'data_1995_2004']
data_1995_2005 = d[ 'data_1995_2005']
data_1995_2006 = d[ 'data_1995_2006']
data_1995_2007 = d[ 'data_1995_2007']
data_1995_2008 = d[ 'data_1995_2008']
data_1995_2009 = d[ 'data_1995_2009']
data_1995_2010 = d[ 'data_1995_2010']
data_1995_2011 = d[ 'data_1995_2011']
data_1995_2012 = d[ 'data_1995_2012']
data_1995_2013 = d[ 'data_1995_2013']
data_1995_2014 = d[ 'data_1995_2014']
data_1995_2015 = d[ 'data_1995_2015']
data_1995_2016 = d[ 'data_1995_2016']
data_1995_2017 = d[ 'data_1995_2017']
data_1996_1997 = d[ 'data_1996_1997']
data_1996_1998 = d[ 'data_1996_1998']
data_1996_1999 = d[ 'data_1996_1999']
data_1996_2000 = d[ 'data_1996_2000']
data_1996_2001 = d[ 'data_1996_2001']
data_1996_2002 = d[ 'data_1996_2002']
data_1996_2003 = d[ 'data_1996_2003']
data_1996_2004 = d[ 'data_1996_2004']
data_1996_2005 = d[ 'data_1996_2005']
data_1996_2006 = d[ 'data_1996_2006']
data_1996_2007 = d[ 'data_1996_2007']
data_1996_2008 = d[ 'data_1996_2008']
data_1996_2009 = d[ 'data_1996_2009']
data_1996_2010 = d[ 'data_1996_2010']
data_1996_2011 = d[ 'data_1996_2011']
data_1996_2012 = d[ 'data_1996_2012']
data_1996_2013 = d[ 'data_1996_2013']
data_1996_2014 = d[ 'data_1996_2014']
data_1996_2015 = d[ 'data_1996_2015']
data_1996_2016 = d[ 'data_1996_2016']
data_1996_2017 = d[ 'data_1996_2017']
data_1997_1998 = d[ 'data_1997_1998']
data_1997_1999 = d[ 'data_1997_1999']
data_1997_2000 = d[ 'data_1997_2000']
data_1997_2001 = d[ 'data_1997_2001']
data_1997_2002 = d[ 'data_1997_2002']
data_1997_2003 = d[ 'data_1997_2003']
data_1997_2004 = d[ 'data_1997_2004']
data_1997_2005 = d[ 'data_1997_2005']
data_1997_2006 = d[ 'data_1997_2006']
data_1997_2007 = d[ 'data_1997_2007']
data_1997_2008 = d[ 'data_1997_2008']
data_1997_2009 = d[ 'data_1997_2009']
data_1997_2010 = d[ 'data_1997_2010']
data_1997_2011 = d[ 'data_1997_2011']
data_1997_2012 = d[ 'data_1997_2012']
data_1997_2013 = d[ 'data_1997_2013']
data_1997_2014 = d[ 'data_1997_2014']
data_1997_2015 = d[ 'data_1997_2015']
data_1997_2016 = d[ 'data_1997_2016']
data_1997_2017 = d[ 'data_1997_2017']
data_1998_1999 = d[ 'data_1998_1999']
data_1998_2000 = d[ 'data_1998_2000']
data_1998_2001 = d[ 'data_1998_2001']
data_1998_2002 = d[ 'data_1998_2002']
data_1998_2003 = d[ 'data_1998_2003']
data_1998_2004 = d[ 'data_1998_2004']
data_1998_2005 = d[ 'data_1998_2005']
data_1998_2006 = d[ 'data_1998_2006']
data_1998_2007 = d[ 'data_1998_2007']
data_1998_2008 = d[ 'data_1998_2008']
data_1998_2009 = d[ 'data_1998_2009']
data_1998_2010 = d[ 'data_1998_2010']
data_1998_2011 = d[ 'data_1998_2011']
data_1998_2012 = d[ 'data_1998_2012']
data_1998_2013 = d[ 'data_1998_2013']
data_1998_2014 = d[ 'data_1998_2014']
data_1998_2015 = d[ 'data_1998_2015']
data_1998_2016 = d[ 'data_1998_2016']
data_1998_2017 = d[ 'data_1998_2017']
data_1999_2000 = d[ 'data_1999_2000']
data_1999_2001 = d[ 'data_1999_2001']
data_1999_2002 = d[ 'data_1999_2002']
data_1999_2003 = d[ 'data_1999_2003']
data_1999_2004 = d[ 'data_1999_2004']
data_1999_2005 = d[ 'data_1999_2005']
data_1999_2006 = d[ 'data_1999_2006']
data_1999_2007 = d[ 'data_1999_2007']
data_1999_2008 = d[ 'data_1999_2008']
data_1999_2009 = d[ 'data_1999_2009']
data_1999_2010 = d[ 'data_1999_2010']
data_1999_2011 = d[ 'data_1999_2011']
data_1999_2012 = d[ 'data_1999_2012']
data_1999_2013 = d[ 'data_1999_2013']
data_1999_2014 = d[ 'data_1999_2014']
data_1999_2015 = d[ 'data_1999_2015']
data_1999_2016 = d[ 'data_1999_2016']
data_1999_2017 = d[ 'data_1999_2017']
data_2000_2001 = d[ 'data_2000_2001']
data_2000_2002 = d[ 'data_2000_2002']
data_2000_2003 = d[ 'data_2000_2003']
data_2000_2004 = d[ 'data_2000_2004']
data_2000_2005 = d[ 'data_2000_2005']
data_2000_2006 = d[ 'data_2000_2006']
data_2000_2007 = d[ 'data_2000_2007']
data_2000_2008 = d[ 'data_2000_2008']
data_2000_2009 = d[ 'data_2000_2009']
data_2000_2010 = d[ 'data_2000_2010']
data_2000_2011 = d[ 'data_2000_2011']
data_2000_2012 = d[ 'data_2000_2012']
data_2000_2013 = d[ 'data_2000_2013']
data_2000_2014 = d[ 'data_2000_2014']
data_2000_2015 = d[ 'data_2000_2015']
data_2000_2016 = d[ 'data_2000_2016']
data_2000_2017 = d[ 'data_2000_2017']
data_2001_2002 = d[ 'data_2001_2002']
data_2001_2003 = d[ 'data_2001_2003']
data_2001_2004 = d[ 'data_2001_2004']
data_2001_2005 = d[ 'data_2001_2005']
data_2001_2006 = d[ 'data_2001_2006']
data_2001_2007 = d[ 'data_2001_2007']
data_2001_2008 = d[ 'data_2001_2008']
data_2001_2009 = d[ 'data_2001_2009']
data_2001_2010 = d[ 'data_2001_2010']
data_2001_2011 = d[ 'data_2001_2011']
data_2001_2012 = d[ 'data_2001_2012']
data_2001_2013 = d[ 'data_2001_2013']
data_2001_2014 = d[ 'data_2001_2014']
data_2001_2015 = d[ 'data_2001_2015']
data_2001_2016 = d[ 'data_2001_2016']
data_2001_2017 = d[ 'data_2001_2017']
data_2002_2003 = d[ 'data_2002_2003']
data_2002_2004 = d[ 'data_2002_2004']
data_2002_2005 = d[ 'data_2002_2005']
data_2002_2006 = d[ 'data_2002_2006']
data_2002_2007 = d[ 'data_2002_2007']
data_2002_2008 = d[ 'data_2002_2008']
data_2002_2009 = d[ 'data_2002_2009']
data_2002_2010 = d[ 'data_2002_2010']
data_2002_2011 = d[ 'data_2002_2011']
data_2002_2012 = d[ 'data_2002_2012']
data_2002_2013 = d[ 'data_2002_2013']
data_2002_2014 = d[ 'data_2002_2014']
data_2002_2015 = d[ 'data_2002_2015']
data_2002_2016 = d[ 'data_2002_2016']
data_2002_2017 = d[ 'data_2002_2017']
data_2003_2004 = d[ 'data_2003_2004']
data_2003_2005 = d[ 'data_2003_2005']
data_2003_2006 = d[ 'data_2003_2006']
data_2003_2007 = d[ 'data_2003_2007']
data_2003_2008 = d[ 'data_2003_2008']
data_2003_2009 = d[ 'data_2003_2009']
data_2003_2010 = d[ 'data_2003_2010']
data_2003_2011 = d[ 'data_2003_2011']
data_2003_2012 = d[ 'data_2003_2012']
data_2003_2013 = d[ 'data_2003_2013']
data_2003_2014 = d[ 'data_2003_2014']
data_2003_2015 = d[ 'data_2003_2015']
data_2003_2016 = d[ 'data_2003_2016']
data_2003_2017 = d[ 'data_2003_2017']
data_2004_2005 = d[ 'data_2004_2005']
data_2004_2006 = d[ 'data_2004_2006']
data_2004_2007 = d[ 'data_2004_2007']
data_2004_2008 = d[ 'data_2004_2008']
data_2004_2009 = d[ 'data_2004_2009']
data_2004_2010 = d[ 'data_2004_2010']
data_2004_2011 = d[ 'data_2004_2011']
data_2004_2012 = d[ 'data_2004_2012']
data_2004_2013 = d[ 'data_2004_2013']
data_2004_2014 = d[ 'data_2004_2014']
data_2004_2015 = d[ 'data_2004_2015']
data_2004_2016 = d[ 'data_2004_2016']
data_2004_2017 = d[ 'data_2004_2017']
data_2005_2006 = d[ 'data_2005_2006']
data_2005_2007 = d[ 'data_2005_2007']
data_2005_2008 = d[ 'data_2005_2008']
data_2005_2009 = d[ 'data_2005_2009']
data_2005_2010 = d[ 'data_2005_2010']
data_2005_2011 = d[ 'data_2005_2011']
data_2005_2012 = d[ 'data_2005_2012']
data_2005_2013 = d[ 'data_2005_2013']
data_2005_2014 = d[ 'data_2005_2014']
data_2005_2015 = d[ 'data_2005_2015']
data_2005_2016 = d[ 'data_2005_2016']
data_2005_2017 = d[ 'data_2005_2017']
data_2006_2007 = d[ 'data_2006_2007']
data_2006_2008 = d[ 'data_2006_2008']
data_2006_2009 = d[ 'data_2006_2009']
data_2006_2010 = d[ 'data_2006_2010']
data_2006_2011 = d[ 'data_2006_2011']
data_2006_2012 = d[ 'data_2006_2012']
data_2006_2013 = d[ 'data_2006_2013']
data_2006_2014 = d[ 'data_2006_2014']
data_2006_2015 = d[ 'data_2006_2015']
data_2006_2016 = d[ 'data_2006_2016']
data_2006_2017 = d[ 'data_2006_2017']
data_2007_2008 = d[ 'data_2007_2008']
data_2007_2009 = d[ 'data_2007_2009']
data_2007_2010 = d[ 'data_2007_2010']
data_2007_2011 = d[ 'data_2007_2011']
data_2007_2012 = d[ 'data_2007_2012']
data_2007_2013 = d[ 'data_2007_2013']
data_2007_2014 = d[ 'data_2007_2014']
data_2007_2015 = d[ 'data_2007_2015']
data_2007_2016 = d[ 'data_2007_2016']
data_2007_2017 = d[ 'data_2007_2017']
data_2008_2009 = d[ 'data_2008_2009']
data_2008_2010 = d[ 'data_2008_2010']
data_2008_2011 = d[ 'data_2008_2011']
data_2008_2012 = d[ 'data_2008_2012']
data_2008_2013 = d[ 'data_2008_2013']
data_2008_2014 = d[ 'data_2008_2014']
data_2008_2015 = d[ 'data_2008_2015']
data_2008_2016 = d[ 'data_2008_2016']
data_2008_2017 = d[ 'data_2008_2017']
data_2009_2010 = d[ 'data_2009_2010']
data_2009_2011 = d[ 'data_2009_2011']
data_2009_2012 = d[ 'data_2009_2012']
data_2009_2013 = d[ 'data_2009_2013']
data_2009_2014 = d[ 'data_2009_2014']
data_2009_2015 = d[ 'data_2009_2015']
data_2009_2016 = d[ 'data_2009_2016']
data_2009_2017 = d[ 'data_2009_2017']
data_2010_2011 = d[ 'data_2010_2011']
data_2010_2012 = d[ 'data_2010_2012']
data_2010_2013 = d[ 'data_2010_2013']
data_2010_2014 = d[ 'data_2010_2014']
data_2010_2015 = d[ 'data_2010_2015']
data_2010_2016 = d[ 'data_2010_2016']
data_2010_2017 = d[ 'data_2010_2017']
data_2011_2012 = d[ 'data_2011_2012']
data_2011_2013 = d[ 'data_2011_2013']
data_2011_2014 = d[ 'data_2011_2014']
data_2011_2015 = d[ 'data_2011_2015']
data_2011_2016 = d[ 'data_2011_2016']
data_2011_2017 = d[ 'data_2011_2017']
data_2012_2013 = d[ 'data_2012_2013']
data_2012_2014 = d[ 'data_2012_2014']
data_2012_2015 = d[ 'data_2012_2015']
data_2012_2016 = d[ 'data_2012_2016']
data_2012_2017 = d[ 'data_2012_2017']
data_2013_2014 = d[ 'data_2013_2014']
data_2013_2015 = d[ 'data_2013_2015']
data_2013_2016 = d[ 'data_2013_2016']
data_2013_2017 = d[ 'data_2013_2017']
data_2014_2015 = d[ 'data_2014_2015']
data_2014_2016 = d[ 'data_2014_2016']
data_2014_2017 = d[ 'data_2014_2017']
data_2015_2016 = d[ 'data_2015_2016']
data_2015_2017 = d[ 'data_2015_2017']
data_2016_2017 = d[ 'data_2016_2017']

In [39]:
AllYearsforCSVExport =[data_1995_1996,
data_1995_1997,
data_1995_1998,
data_1995_1999,
data_1995_2000,
data_1995_2001,
data_1995_2002,
data_1995_2003,
data_1995_2004,
data_1995_2005,
data_1995_2006,
data_1995_2007,
data_1995_2008,
data_1995_2009,
data_1995_2010,
data_1995_2011,
data_1995_2012,
data_1995_2013,
data_1995_2014,
data_1995_2015,
data_1995_2016,
data_1995_2017,
data_1996_1997,
data_1996_1998,
data_1996_1999,
data_1996_2000,
data_1996_2001,
data_1996_2002,
data_1996_2003,
data_1996_2004,
data_1996_2005,
data_1996_2006,
data_1996_2007,
data_1996_2008,
data_1996_2009,
data_1996_2010,
data_1996_2011,
data_1996_2012,
data_1996_2013,
data_1996_2014,
data_1996_2015,
data_1996_2016,
data_1996_2017,
data_1997_1998,
data_1997_1999,
data_1997_2000,
data_1997_2001,
data_1997_2002,
data_1997_2003,
data_1997_2004,
data_1997_2005,
data_1997_2006,
data_1997_2007,
data_1997_2008,
data_1997_2009,
data_1997_2010,
data_1997_2011,
data_1997_2012,
data_1997_2013,
data_1997_2014,
data_1997_2015,
data_1997_2016,
data_1997_2017,
data_1998_1999,
data_1998_2000,
data_1998_2001,
data_1998_2002,
data_1998_2003,
data_1998_2004,
data_1998_2005,
data_1998_2006,
data_1998_2007,
data_1998_2008,
data_1998_2009,
data_1998_2010,
data_1998_2011,
data_1998_2012,
data_1998_2013,
data_1998_2014,
data_1998_2015,
data_1998_2016,
data_1998_2017,
data_1999_2000,
data_1999_2001,
data_1999_2002,
data_1999_2003,
data_1999_2004,
data_1999_2005,
data_1999_2006,
data_1999_2007,
data_1999_2008,
data_1999_2009,
data_1999_2010,
data_1999_2011,
data_1999_2012,
data_1999_2013,
data_1999_2014,
data_1999_2015,
data_1999_2016,
data_1999_2017,
data_2000_2001,
data_2000_2002,
data_2000_2003,
data_2000_2004,
data_2000_2005,
data_2000_2006,
data_2000_2007,
data_2000_2008,
data_2000_2009,
data_2000_2010,
data_2000_2011,
data_2000_2012,
data_2000_2013,
data_2000_2014,
data_2000_2015,
data_2000_2016,
data_2000_2017,
data_2001_2002,
data_2001_2003,
data_2001_2004,
data_2001_2005,
data_2001_2006,
data_2001_2007,
data_2001_2008,
data_2001_2009,
data_2001_2010,
data_2001_2011,
data_2001_2012,
data_2001_2013,
data_2001_2014,
data_2001_2015,
data_2001_2016,
data_2001_2017,
data_2002_2003,
data_2002_2004,
data_2002_2005,
data_2002_2006,
data_2002_2007,
data_2002_2008,
data_2002_2009,
data_2002_2010,
data_2002_2011,
data_2002_2012,
data_2002_2013,
data_2002_2014,
data_2002_2015,
data_2002_2016,
data_2002_2017,
data_2003_2004,
data_2003_2005,
data_2003_2006,
data_2003_2007,
data_2003_2008,
data_2003_2009,
data_2003_2010,
data_2003_2011,
data_2003_2012,
data_2003_2013,
data_2003_2014,
data_2003_2015,
data_2003_2016,
data_2003_2017,
data_2004_2005,
data_2004_2006,
data_2004_2007,
data_2004_2008,
data_2004_2009,
data_2004_2010,
data_2004_2011,
data_2004_2012,
data_2004_2013,
data_2004_2014,
data_2004_2015,
data_2004_2016,
data_2004_2017,
data_2005_2006,
data_2005_2007,
data_2005_2008,
data_2005_2009,
data_2005_2010,
data_2005_2011,
data_2005_2012,
data_2005_2013,
data_2005_2014,
data_2005_2015,
data_2005_2016,
data_2005_2017,
data_2006_2007,
data_2006_2008,
data_2006_2009,
data_2006_2010,
data_2006_2011,
data_2006_2012,
data_2006_2013,
data_2006_2014,
data_2006_2015,
data_2006_2016,
data_2006_2017,
data_2007_2008,
data_2007_2009,
data_2007_2010,
data_2007_2011,
data_2007_2012,
data_2007_2013,
data_2007_2014,
data_2007_2015,
data_2007_2016,
data_2007_2017,
data_2008_2009,
data_2008_2010,
data_2008_2011,
data_2008_2012,
data_2008_2013,
data_2008_2014,
data_2008_2015,
data_2008_2016,
data_2008_2017,
data_2009_2010,
data_2009_2011,
data_2009_2012,
data_2009_2013,
data_2009_2014,
data_2009_2015,
data_2009_2016,
data_2009_2017,
data_2010_2011,
data_2010_2012,
data_2010_2013,
data_2010_2014,
data_2010_2015,
data_2010_2016,
data_2010_2017,
data_2011_2012,
data_2011_2013,
data_2011_2014,
data_2011_2015,
data_2011_2016,
data_2011_2017,
data_2012_2013,
data_2012_2014,
data_2012_2015,
data_2012_2016,
data_2012_2017,
data_2013_2014,
data_2013_2015,
data_2013_2016,
data_2013_2017,
data_2014_2015,
data_2014_2016,
data_2014_2017,
data_2015_2016,
data_2015_2017,
data_2016_2017]

In [40]:
for i in range(0,len(AllYearsforCSVExport)):
AllYearsforCSVExport[i].to_csv('E:\\Documents\\UKHousePrices\\YearToYearDataALL\\' + str(i) + '.csv')

In [41]:
data_2016_2017.head()

Out[41]:
0 2016 300900.000 2017 300500.0 Rest of UK
1 2016 460020.000 2017 470000.0 Rest of UK
2 2016 422002.560 2017 385000.0 Rest of UK
3 2016 277100.000 2017 295000.0 Rest of UK
4 2016 384954.375 2017 435600.0 Rest of UK

#### We now import each data table into our R magic for Hexbin plots¶

In [42]:
%R -i data_1995_1996,data_1995_1997,data_1995_1998,data_1995_1999,data_1995_2000,data_1995_2001,data_1995_2002,data_1995_2003,data_1995_2004,data_1995_2005,data_1995_2006,data_1995_2007,data_1995_2008,data_1995_2009,data_1995_2010,data_1995_2011,data_1995_2012,data_1995_2013,data_1995_2014,data_1995_2015,data_1995_2016,data_1995_2017,data_1996_1997,data_1996_1998,data_1996_1999,data_1996_2000,data_1996_2001,data_1996_2002,data_1996_2003,data_1996_2004,data_1996_2005,data_1996_2006,data_1996_2007,data_1996_2008,data_1996_2009,data_1996_2010,data_1996_2011,data_1996_2012,data_1996_2013,data_1996_2014,data_1996_2015,data_1996_2016,data_1996_2017,data_1997_1998,data_1997_1999,data_1997_2000,data_1997_2001,data_1997_2002,data_1997_2003,data_1997_2004,data_1997_2005,data_1997_2006,data_1997_2007,data_1997_2008,data_1997_2009,data_1997_2010,data_1997_2011,data_1997_2012,data_1997_2013,data_1997_2014,data_1997_2015,data_1997_2016,data_1997_2017,data_1998_1999,data_1998_2000,data_1998_2001,data_1998_2002,data_1998_2003,data_1998_2004,data_1998_2005,data_1998_2006,data_1998_2007,data_1998_2008,data_1998_2009,data_1998_2010,data_1998_2011,data_1998_2012,data_1998_2013,data_1998_2014,data_1998_2015,data_1998_2016,data_1998_2017,data_1999_2000,data_1999_2001,data_1999_2002,data_1999_2003,data_1999_2004,data_1999_2005,data_1999_2006,data_1999_2007,data_1999_2008,data_1999_2009,data_1999_2010,data_1999_2011,data_1999_2012,data_1999_2013,data_1999_2014,data_1999_2015,data_1999_2016,data_1999_2017,data_2000_2001,data_2000_2002,data_2000_2003,data_2000_2004,data_2000_2005,data_2000_2006,data_2000_2007,data_2000_2008,data_2000_2009,data_2000_2010,data_2000_2011,data_2000_2012,data_2000_2013,data_2000_2014,data_2000_2015,data_2000_2016,data_2000_2017,data_2001_2002,data_2001_2003,data_2001_2004,data_2001_2005,data_2001_2006,data_2001_2007,data_2001_2008,data_2001_2009,data_2001_2010,data_2001_2011,data_2001_2012,data_2001_2013,data_2001_2014,data_2001_2015,data_2001_2016,data_2001_2017,data_2002_2003,data_2002_2004,data_2002_2005,data_2002_2006,data_2002_2007,data_2002_2008,data_2002_2009,data_2002_2010,data_2002_2011,data_2002_2012,data_2002_2013,data_2002_2014,data_2002_2015,data_2002_2016,data_2002_2017,data_2003_2004,data_2003_2005,data_2003_2006,data_2003_2007,data_2003_2008,data_2003_2009,data_2003_2010,data_2003_2011,data_2003_2012,data_2003_2013,data_2003_2014,data_2003_2015,data_2003_2016,data_2003_2017,data_2004_2005,data_2004_2006,data_2004_2007,data_2004_2008,data_2004_2009,data_2004_2010,data_2004_2011,data_2004_2012,data_2004_2013,data_2004_2014,data_2004_2015,data_2004_2016,data_2004_2017,data_2005_2006,data_2005_2007,data_2005_2008,data_2005_2009,data_2005_2010,data_2005_2011,data_2005_2012,data_2005_2013,data_2005_2014,data_2005_2015,data_2005_2016,data_2005_2017,data_2006_2007,data_2006_2008,data_2006_2009,data_2006_2010,data_2006_2011,data_2006_2012,data_2006_2013,data_2006_2014,data_2006_2015,data_2006_2016,data_2006_2017,data_2007_2008,data_2007_2009,data_2007_2010,data_2007_2011,data_2007_2012,data_2007_2013,data_2007_2014,data_2007_2015,data_2007_2016,data_2007_2017,data_2008_2009,data_2008_2010,data_2008_2011,data_2008_2012,data_2008_2013,data_2008_2014,data_2008_2015,data_2008_2016,data_2008_2017,data_2009_2010,data_2009_2011,data_2009_2012,data_2009_2013,data_2009_2014,data_2009_2015,data_2009_2016,data_2009_2017,data_2010_2011,data_2010_2012,data_2010_2013,data_2010_2014,data_2010_2015,data_2010_2016,data_2010_2017,data_2011_2012,data_2011_2013,data_2011_2014,data_2011_2015,data_2011_2016,data_2011_2017,data_2012_2013,data_2012_2014,data_2012_2015,data_2012_2016,data_2012_2017,data_2013_2014,data_2013_2015,data_2013_2016,data_2013_2017,data_2014_2015,data_2014_2016,data_2014_2017,data_2015_2016,data_2015_2017,data_2016_2017


### I would not recommend running all comparisons but rather select one start year at a time¶

In [132]:
%%R -w 4 -h 4 --units in -r 200

data_tables_Years <- list(data_1995_1996,data_1995_1997,data_1995_1998,data_1995_1999,data_1995_2000,data_1995_2001,data_1995_2002,data_1995_2003,data_1995_2004,data_1995_2005,data_1995_2006,data_1995_2007,data_1995_2008,data_1995_2009,data_1995_2010,data_1995_2011,data_1995_2012,data_1995_2013,data_1995_2014,data_1995_2015,data_1995_2016,data_1995_2017)
#data_1996_1997,data_1996_1998,data_1996_1999,data_1996_2000,data_1996_2001,data_1996_2002,data_1996_2003,data_1996_2004,data_1996_2005,data_1996_2006,data_1996_2007,data_1996_2008,data_1996_2009,data_1996_2010,data_1996_2011,data_1996_2012,data_1996_2013,data_1996_2014,data_1996_2015,data_1996_2016,data_1996_2017
#data_1997_1998,data_1997_1999,data_1997_2000,data_1997_2001,data_1997_2002,data_1997_2003,data_1997_2004,data_1997_2005,data_1997_2006,data_1997_2007,data_1997_2008,data_1997_2009,data_1997_2010,data_1997_2011,data_1997_2012,data_1997_2013,data_1997_2014,data_1997_2015,data_1997_2016,data_1997_2017
#data_1998_1999,data_1998_2000,data_1998_2001,data_1998_2002,data_1998_2003,data_1998_2004,data_1998_2005,data_1998_2006,data_1998_2007,data_1998_2008,data_1998_2009,data_1998_2010,data_1998_2011,data_1998_2012,data_1998_2013,data_1998_2014,data_1998_2015,data_1998_2016,data_1998_2017
#data_1999_2000,data_1999_2001,data_1999_2002,data_1999_2003,data_1999_2004,data_1999_2005,data_1999_2006,data_1999_2007,data_1999_2008,data_1999_2009,data_1999_2010,data_1999_2011,data_1999_2012,data_1999_2013,data_1999_2014,data_1999_2015,data_1999_2016,data_1999_2017
#data_2000_2001,data_2000_2002,data_2000_2003,data_2000_2004,data_2000_2005,data_2000_2006,data_2000_2007,data_2000_2008,data_2000_2009,data_2000_2010,data_2000_2011,data_2000_2012,data_2000_2013,data_2000_2014,data_2000_2015,data_2000_2016,data_2000_2017
#data_2001_2002,data_2001_2003,data_2001_2004,data_2001_2005,data_2001_2006,data_2001_2007,data_2001_2008,data_2001_2009,data_2001_2010,data_2001_2011,data_2001_2012,data_2001_2013,data_2001_2014,data_2001_2015,data_2001_2016,data_2001_2017
#data_2002_2003,data_2002_2004,data_2002_2005,data_2002_2006,data_2002_2007,data_2002_2008,data_2002_2009,data_2002_2010,data_2002_2011,data_2002_2012,data_2002_2013,data_2002_2014,data_2002_2015,data_2002_2016,data_2002_2017
#data_2003_2004,data_2003_2005,data_2003_2006,data_2003_2007,data_2003_2008,data_2003_2009,data_2003_2010,data_2003_2011,data_2003_2012,data_2003_2013,data_2003_2014,data_2003_2015,data_2003_2016,data_2003_2017
#data_2004_2005,data_2004_2006,data_2004_2007,data_2004_2008,data_2004_2009,data_2004_2010,data_2004_2011,data_2004_2012,data_2004_2013,data_2004_2014,data_2004_2015,data_2004_2016,data_2004_2017
#data_2005_2006,data_2005_2007,data_2005_2008,data_2005_2009,data_2005_2010,data_2005_2011,data_2005_2012,data_2005_2013,data_2005_2014,data_2005_2015,data_2005_2016,data_2005_2017,data_2006_2007
#data_2006_2008,data_2006_2009,data_2006_2010,data_2006_2011,data_2006_2012,data_2006_2013,data_2006_2014,data_2006_2015,data_2006_2016,data_2006_2017
#data_2007_2008,data_2007_2009,data_2007_2010,data_2007_2011,data_2007_2012,data_2007_2013,data_2007_2014,data_2007_2015,data_2007_2016,data_2007_2017
#data_2008_2009,data_2008_2010,data_2008_2011,data_2008_2012,data_2008_2013,data_2008_2014,data_2008_2015,data_2008_2016,data_2008_2017
#data_2009_2010,data_2009_2011,data_2009_2012,data_2009_2013,data_2009_2014,data_2009_2015,data_2009_2016,data_2009_2017
#data_2010_2011,data_2010_2012,data_2010_2013,data_2010_2014,data_2010_2015,data_2010_2016,data_2010_2017
#data_2011_2012,data_2011_2013,data_2011_2014,data_2011_2015,data_2011_2016,data_2011_2017
#data_2012_2013,data_2012_2014,data_2012_2015,data_2012_2016,data_2012_2017
#data_2013_2014,data_2013_2015,data_2013_2016,data_2013_2017
#data_2014_2015,data_2014_2016,data_2014_2017
#data_2015_2016,data_2015_2017
#data_2016_2017

for (j in data_tables_Years){

dataLondon <- j[ which(j$LondonCheck_x == 'GREATER LONDON'),] dataRestofUK <- j[ which(j$LondonCheck_x == 'Rest of UK'),]

x1 = dataLondon$AdjustedPrice_x y1 = dataLondon$AdjustedPrice_y

linmodel1 = lm(y2~x2)

coeffs1 = summary(linmodel1)
intercept1 <- coeffs1$coefficients[1] slope1 <- coeffs1$coefficients[2]

line1 <- (slope1*x1) + intercept1

df_plot1 <- data.frame(x1,y1, line1)

x2 = dataRestofUK$AdjustedPrice_x y2 = dataRestofUK$AdjustedPrice_y

linmodel2 = lm(y2~x2)

coeffs2 = summary(linmodel2)
intercept2 <- coeffs2$coefficients[1] slope2 <- coeffs2$coefficients[2]

line2 <- (slope2*x2) + intercept2

df_plot2 <- data.frame(x2,y2, line2)

hbinALL <- ggplot() +
stat_binhex(data=dataLondon,aes(x=x1,y=y1, alpha=0.5), fill='#A833FF',line = '#fffff',bins = 75) +
stat_binhex(data=dataRestofUK,aes(x=x2,y=y2, alpha=0.5), fill='#33FFA6', bins = 75) +
guides(fill = FALSE, alpha=FALSE) +
ggtitle( paste('Price of the Same House in', toString(unique(dataLondon$Year_x)) ,'Sold Again in' , toString(unique(dataLondon$Year_y)), sep = ' ' ) ) +
scale_x_continuous(name=paste('Price', toString(unique(dataLondon$Year_x)), '£', sep = ' '), labels = scales::comma, limits = c(0,2500000)) + scale_y_continuous(name=paste('Price', toString(unique(dataLondon$Year_y)), '£', sep = ' '), labels = scales::comma, limits = c(0,10000000)) +
theme(panel.background = element_rect(fill='black' ,colour='#ababab'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
text = element_text(size=8
)) +
# geom_line(color = '#ee77ee', data = df_plot1, aes(x=x1,y=line1),
#      title = element_text(size=2)) +
# geom_line(color = '#36e3e3', data = df_plot2, aes(x=x2,y=line2)) +

annotate(geom = 'text', label = 'London', color = '#A833FF', x=500000, y = 9000000) +
annotate(geom = 'text', label = 'Rest of UK', color = '#33FFA6', x= 2000000, y = 9000000)

#plot(hbinALL)

#hbinAll <- ggplotly(hbintest)

}