Skip to content

Instantly share code, notes, and snippets.

@pcomans
Created July 20, 2012 15:32
Show Gist options
  • Save pcomans/3151351 to your computer and use it in GitHub Desktop.
Save pcomans/3151351 to your computer and use it in GitHub Desktop.
SITE TOTAL_VISITS CHARGE_FREE PERCENT_CHANGE
British Museum 5842138 F 4.90%
Tate Modern 5061172 F 7.00%
National Gallery 4954914 F 3.70%
Natural History Museum 4647613 F 13.20%
Science Museum (South Kensington) 2751902 F -0.50%
V&A (South Kensington) 2629065 F 16.00%
National Maritime Museum 2419802 F 2.19%
Tower of London (HRP) 2414541 C 1.04%
St Paul's Cathedral 1892467 F/C 4.00%
National Portrait Gallery 1819442 F -7.00%
Tate Britain 1665291 F 11.00%
British Library 1454612 F 5.00%
Westminster Abbey 1394427 F/C -3.80%
National Galleries of Scotland (Edinburgh sites) 1281465 F/C 10.18%
Old Royal Naval College Greenwich 1274957 F 28.00%
Edinburgh Castle (Historic Scotland) 1210248 F/C 1.00%
Chester Zoo 1154285 C -6.80%
Royal Botanic Gardens Kew 1141973 C -12.19%
Kelvingrove Art Gallery & Museum (Glasgow) 1070521 F -21.75%
Imperial War Museum (London) 1069358 F 21.00%
Roman Baths & Pump Room Bath 1054621 C 2.00%
Canterbury Cathedral 1033463 F/C 2.00%
Merseyside Maritime Museum 1027475 F 9.00%
ZSL London Zoo 1011257 F/C -4.95%
Stonehenge (EH) 1009973 C 2.00%
Eden Project 1000511 C -2.70%
Royal Horticultural Society Wisley 803986 F/C -16.20%
World Museum Liverpool (National Museums Liverpool) 748065 F 23.00%
Chatsworth House Trust (THE) 716616 C 9.75%
Royal Botanic Garden Edinburgh 707244 F 21.70%
Houses of Parliament 703255 F/C -27.00%
National Railway Museum 624145 F -16.00%
National Museum of Scotland (National Museums Scotland) 619254 F 5.00%
Tate Liverpool 615596 F 14.00%
St Fagans: National History Museum (Wales) 610155 F -2.89%
Leeds Castle (THE) 559261 C -13.00%
Hampton Court Palace (HRP) 550225 C -9.80%
National War Museum (National Museums Scotland) 528776 F 7.00%
National Media Museum 526914 F -12.80%
Blenheim Palace (THE) 524593 C -2.30%
York Minster ** 512075 F/C -2.50%
Gallery of Modern Art (Glasgow Museums) 490872 F -8.58%
International Slavery Museum (National Museums Liverpool) 458569 F 28.00%
The Falkirk Wheel (British Waterways) 439072 F/C -8.00%
ZSL Whipsnade Zoo 428684 F/C -9.60%
V&A Museum of Childhood 403549 F 4.00%
Wakehurst Place (NT) 402180 C -12.00%
Imperial War Museum Duxford 399262 C 3.00%
Stirling Castle (Historic Scotland) 377204 F/C -2.00%
Stourhead (NT) 361730 F/C 1.00%
National Museum Cardiff 358480 F -3.94%
Beaulieu (THE) 354048 C 0.60%
Dover Castle (EH) 349182 C 15.00%
Fountains Abbey & Studley Royal (NT) 342499 F/C -2.00%
Churchill War Rooms 328621 C 5.00%
Waddesdon Manor (NT) 323450 F/C -7.00%
Urquhart Castle (Historic Scotland) 286262 F/C 1.00%
Attingham Park (NT) 277428 F/C 7.00%
Royal Armouries Museum (Leeds) 274768 F 1.20%
Belton House (NT) 264239 F/C 6.00%
St MichaelÕs Mount (NT) 264072 F/C 10.00%
National Waterfront Museum (Wales) 263484 F 2.17%
Kensington Palace (HRP) 251817 C -7.63%
Walker Art Gallery (National Museums Liverpool) 251543 F 17.00%
Harewood House (THE) 247745 F/C 2.78%
Imperial War Museum (North) 247600 F 5.00%
Calke Abbey (NT) 247207 F/C 3.00%
Royal Horticultural Society Harlow Carr 246563 F/C -4.80%
Polesden Lacey (NT) 246537 F/C -6.00%
PeopleÕs Palace (Glasgow Museums) 245770 F -8.50%
HMS Belfast 240769 C -8.00%
Larrybane (NT) 237420 F/C -2.00%
Cliveden (NT) 233913 F/C 13.00%
Osborne House (EH) 232276 C -3.00%
Anglesey Abbey (NT) 231289 F/C 5.00%
Penrhyn Castle (NT) 230454 F/C 1.00%
Castle Howard (THE) 216566 C -7.00%
Nymans Garden (NT) 211036 F/C -5.00%
Lanhydrock (NT) 210362 F/C -2.00%
Tate St Ives 207254 C -3.00%
Kingston Lacy (NT) 203488 F/C 6.00%
Lady Lever Art Gallery (National Museums Liverpool) 200937 F 4.00%
Wallington Park (NT) 199024 F/C 1.00%
Sheffield Park (NT) 197202 F/C -6.00%
Dunham Massey (NT) 196219 F/C 27.00%
National Railway Museum ÒLocomotionÓ Shildon 194106 F 23.60%
Bodnant Garden (NT) 191069 F/C -3.00%
Tintagel Castle Cornwall (EH) 190246 C -4.00%
Corfe Castle (NT) 189647 F/C -5.00%
Cragside Estate (NT) 189280 F/C -16.00%
Mottisfont (NT) 189072 F/C 17.00%
Chartwell (NT) 188705 F/C -3.00%
Burrell Collection (Glasgow Museums) 187756 F -7.58%
Bodiam Castle (NT) 176193 F/C -6.00%
Culzean Castle & Country Park (National Trust for Scotland) 175549 F/C 0.20%
Hardwick Hall (NT) 165150 F/C 1.00%
Killerton (NT) 161196 F/C 11.00%
Museum of Transport (Glasgow Museums) 160571 F -65.76%
Ickworth (NT) 159777 F/C -11.00%
Sudbury Hall (NT) 159178 F/C -4.00%
Claremont Landscape Garden (NT) 157270 F/C -2.00%
Pier MasterÕs House (National Museums Liverpool) 157054 F 15.00%
Big Pit: National Coal Museum (Wales) 155631 F -5.00%
Sissinghurst (NT) 154530 F/C -21.00%
Mount Stewart (NT) 153552 F/C 15.00%
Hidcote Manor Garden (NT) 148680 F/C -7.00%
St Mungo Museum of Religious Art (Glasgow Museums) 143017 F -0.93%
Royal Horticultural Society Rosemoor 140831 F/C -1.10%
Erddig (NT) 140563 F/C 7.00%
1066 Battle of Hastings:Abbey & Battlefield (EH) 136504 C 1.00%
Dyrham Park (NT) 135920 F/C -1.00%
Home Farm Wimpole (NT) 132477 F/C -5.00%
Royal Horticultural Society Hyde Hall 131780 F/C -1.50%
Baddesley Clinton (NT) 130696 F/C 0.00%
Brownsea Island (NT) 130114 F/C 2.00%
Cotehele (NT) 129486 F/C -2.00%
Kenwood House London (EH) 128783 F 11.00%
Dunster (NT) 128242 F/C -5.00%
Castle Drago Estate (NT) 127123 F/C 1.00%
Trelissick (NT) 126705 F/C 4.00%
Tyntesfield (NT) 123440 F/C 18.00%
Montacute House (NT) 125008 F/C 12.00%
CliffordÕs Tower York (EH) 122138 C 3.00%
Audley End House & Gardens Essex (EH) 120102 C 21.00%
Carisbrooke Castle Isle of Wight (EH) 118354 C -8.00%
Whitby Abbey North Yorkshire (EH) 117289 C -11.00%
Anderton Boat Lift (British Waterways) 116922 F/C 3.00%
Natural History Museum at Tring 113859 F -3.50%
ProvandÕs Lordship (Glasgow Museums) 107044 F -8.14%
National Conservation Centre (National Museums Liverpool) 103548 F -17.00%
Burghley House (THE) 96855 C -1.60%
Royal Armouries Museum (Fort Nelson Portsmouth) 70540 F -8.05%
Woburn Abbey & Gardens (THE) 68930 C 4.54%
Sudley House (National Museums Liverpool) 68463 F 6.00%
St PeterÕs Church Sandwich Kent (CCT) 66366 F -3.20%
St PeterÕs Church Sudbury Suffolk (CCT) 59567 F 1.00%
St MaryÕs Church Shrewsbury Shropshire (CCT) 49690 F -16.00%
Scotland Street School Museum (Glasgow Museums) 49346 F -23.93%
Benmore Botanic Garden (Argyll) (RBGE) 49129 C -5.60%
Holy Trinity Church North Yorkshire (CCT) 48515 F -6.00%
St JohnÕs Church Chichester West Sussex (CCT) 42754 F 5.00%
St Peter & St Paul Church Albury Surrey (CCT) 41743 F 27.70%
All Saints Church Kedleston Derbyshire (CCT) 41731 F -0.70%
St Mary MagdaleneCroome DÕAbitotWorcestershire (CCT) 41322 F 18.00%
All Saints Harewood West Yorkshire (CCT) 37563 F 2.60%
St AndrewÕs Church Hove East Sussex (CCT) 36669 F -23.80%
Dawyck Botanic Garden (Borders) (RBGE) 30158 C -16.50%
Holkham Hall (THE) 29459 F/C 12.30%
Logan Botanic Garden (Galloway) (RBGE) 22131 C -9.90%
Glasgow Museums Resource Centre 9059 F 39.43%
<html>
<head>
<meta charset="utf-8">
<title>Scaffold</title>
<style>
body {
background-color: #F2F2F2;
font-family: Helvetica, Arial, sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<script src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript">
d3.csv("./data.csv", draw)
function draw(data) {
"use strict"
var commaReplacer = new RegExp(",", "g");
var spaceReplacer = new RegExp(" ", "g");
data.forEach(function(o) {
o.SITE = o.SITE.replace(spaceReplacer, " ");
o.TOTAL_VISITS = parseInt(o.TOTAL_VISITS.replace(commaReplacer, ""));
o.PERCENT_CHANGE = parseFloat(o.PERCENT_CHANGE);
o.radius = Math.sqrt(o.TOTAL_VISITS/(Math.PI*800));
});
var margin = {top: 0, right: 40, bottom: 40, left: 0},
width = 1024,
height = 600;
var xScaleFirst = d3.scale.linear()
.domain(d3.extent(data, function(d) { return d.TOTAL_VISITS; }))
.range([0, width - margin.left - margin.right]);
var xScaleSecond = d3.scale.log()
.domain(d3.extent(data, function(d) { return d.TOTAL_VISITS; }))
.range([0, width - margin.left - margin.right]);
var yScale = d3.scale.linear()
.domain(d3.extent(data, function(d) { return d.PERCENT_CHANGE; }))
.range([height - margin.top - margin.bottom, 0]);
var xAxis = d3.svg.axis()
.scale(xScaleFirst)
.orient("bottom")
.tickPadding(8);
var xAxisTwo = d3.svg.axis()
.scale(xScaleSecond)
.orient("bottom")
.tickPadding(8);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.tickPadding(8);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "dot chart")
.append("g")
.attr("class", "drawingarea")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var dataPoints = svg.selectAll(".datapoint")
.data(data)
.enter().append("g")
.attr("class", "datapoint")
.attr("transform", function(d) {
var property = "translate(" + xScaleFirst(d.TOTAL_VISITS) + "," + yScale(d.PERCENT_CHANGE) + ")";
return property;
});
dataPoints.append("title")
.text(function(d) {return d.SITE;});
dataPoints.append("circle")
.attr("r", 5)
.attr("stroke", "black")
.attr("fill", function (d) {
if (d.CHARGE_FREE == "F") {
return "#6AA67F";
} else if (d.CHARGE_FREE == "C") {
return "#D92525";
} else {
return "#F2BF27";
}
});
svg.append("g")
.attr("class", "axis x")
.attr("transform", "translate(0," + yScale.range()[0] + ")")
.call(xAxis);
svg.append("g")
.attr("class", "axis y")
.call(yAxis);
d3.select("#tolog")
.on("click", function(d,i) {
d3.select("svg").selectAll(".datapoint")
.transition()
.duration(2000)
.attr("transform", function(d) {
return "translate(" + xScaleSecond(d.TOTAL_VISITS) + "," + yScale(d.PERCENT_CHANGE) + ")";
});
d3.selectAll(".axis.x").remove();
d3.select(".drawingarea").append("g")
.attr("class", "axis x")
.attr("transform", "translate(0," + yScale.range()[0] + ")")
.call(xAxisTwo);
});
d3.select("#bubblesizes")
.on("click", function(d,i) {
d3.select("svg").selectAll(".datapoint").select("circle")
.transition()
.duration(1000)
.attr("r", function(d) { return d.radius; })
});
}
</script>
<h1>Visitors to museums and galleries in the UK, 2010</h1>
<p>
free = green, charge = red, mixed = yellow
</p>
<p>
<button id="tolog">Logarithmic scaling</button>
<button id="bubblesizes">Resize bubbles</button>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment