Shows the frequency associated with different word patterns contained in Macy's reviews.
Last active
October 27, 2015 03:10
-
-
Save josiahdavis/876c4364b988e863bfdb to your computer and use it in GitHub Desktop.
Complaints in yelp reviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
word | counts | P | N | PR | NR | tfP | tfN | negativity | |
---|---|---|---|---|---|---|---|---|---|
Help | 101 | 22 | 79 | 180 | 185 | 0.561111111 | 0.713513514 | 1.271608242 | |
Associate | 128 | 36 | 92 | 180 | 185 | 0.6 | 0.748648649 | 1.247747748 | |
Time | 154 | 51 | 103 | 180 | 185 | 0.641666667 | 0.778378378 | 1.213057213 | |
Jewelry | 79 | 18 | 61 | 180 | 185 | 0.55 | 0.664864865 | 1.208845209 | |
Management | 44 | 7 | 37 | 180 | 185 | 0.519444444 | 0.6 | 1.155080214 | |
Website | 28 | 5 | 23 | 180 | 185 | 0.513888889 | 0.562162162 | 1.09393718 | |
Macy's Card | 70 | 26 | 44 | 180 | 185 | 0.572222222 | 0.618918919 | 1.081605878 | |
Returns | 25 | 5 | 20 | 180 | 185 | 0.513888889 | 0.554054054 | 1.07815924 | |
Clothing | 122 | 52 | 70 | 180 | 185 | 0.644444444 | 0.689189189 | 1.0694315 | |
Cosmetics | 50 | 18 | 32 | 180 | 185 | 0.55 | 0.586486486 | 1.066339066 | |
Women | 55 | 21 | 34 | 180 | 185 | 0.558333333 | 0.591891892 | 1.060104881 | |
Delivery | 15 | 2 | 13 | 180 | 185 | 0.505555556 | 0.535135135 | 1.058509059 | |
Dillard's | 16 | 3 | 13 | 180 | 185 | 0.508333333 | 0.535135135 | 1.052724856 | |
Display | 11 | 1 | 10 | 180 | 185 | 0.502777778 | 0.527027027 | 1.048230551 | |
Register | 29 | 10 | 19 | 180 | 185 | 0.527777778 | 0.551351351 | 1.044665718 | |
Watches | 36 | 14 | 22 | 180 | 185 | 0.538888889 | 0.559459459 | 1.038172193 | |
Bathroom | 8 | 1 | 7 | 180 | 185 | 0.502777778 | 0.518918919 | 1.032103927 | |
Customer Service | 138 | 65 | 73 | 180 | 185 | 0.680555556 | 0.697297297 | 1.02460011 | |
Men | 69 | 32 | 37 | 180 | 185 | 0.588888889 | 0.6 | 1.018867925 | |
Clean | 36 | 16 | 20 | 180 | 185 | 0.544444444 | 0.554054054 | 1.017650303 | |
Mattress | 3 | 0 | 3 | 180 | 185 | 0.5 | 0.508108108 | 1.016216216 | |
Wedding | 18 | 9 | 9 | 180 | 185 | 0.525 | 0.524324324 | 0.998712999 | |
Lamps | 3 | 2 | 1 | 180 | 185 | 0.505555556 | 0.502702703 | 0.994356994 | |
Bedding | 23 | 12 | 11 | 180 | 185 | 0.533333333 | 0.52972973 | 0.993243243 | |
Furniture | 49 | 25 | 24 | 180 | 185 | 0.569444444 | 0.564864865 | 0.991957811 | |
Fashion | 48 | 25 | 23 | 180 | 185 | 0.569444444 | 0.562162162 | 0.987211602 | |
Kohl's | 3 | 3 | 0 | 180 | 185 | 0.508333333 | 0.5 | 0.983606557 | |
Purse | 12 | 8 | 4 | 180 | 185 | 0.522222222 | 0.510810811 | 0.978148361 | |
Location | 79 | 44 | 35 | 180 | 185 | 0.622222222 | 0.594594595 | 0.955598456 | |
Price | 40 | 25 | 15 | 180 | 185 | 0.569444444 | 0.540540541 | 0.949241925 | |
Quality | 28 | 19 | 9 | 180 | 185 | 0.552777778 | 0.524324324 | 0.948526416 | |
Shoes | 153 | 84 | 69 | 180 | 185 | 0.733333333 | 0.686486486 | 0.936117936 | |
Deal | 368 | 208 | 160 | 180 | 185 | 1.077777778 | 0.932432432 | 0.865143494 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.node text { | |
text-anchor: middle; | |
} | |
text { | |
font: 10px "Helvetica Neue", Helvetica, Arial, sans-serif; | |
pointer-events: none; | |
} | |
circle { | |
fill: #ccc; | |
} | |
.node:hover circle { | |
opacity: 0.8; | |
} | |
.d3-tip { | |
line-height: 1; | |
font: 14px sans-serif; | |
padding: 12px; | |
background: rgba(0, 0, 0, 0.8); | |
color: rgb(185, 185, 185); | |
border-radius: 2px; | |
} | |
/* Creates a small triangle extender for the tooltip */ | |
.d3-tip:after { | |
box-sizing: border-box; | |
display: inline; | |
font-size: 10px; | |
width: 100%; | |
line-height: 1; | |
color: rgba(0, 0, 0, 0.8); | |
content: "\25BC"; | |
position: absolute; | |
text-align: center; | |
} | |
/* Style northward tooltips differently */ | |
.d3-tip.n:after { | |
margin: -1px 0 0 0; | |
top: 100%; | |
left: 0; | |
} | |
</style> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/1.4.0/d3-legend.js"></script> | |
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script> | |
<script> | |
// Modified from the Mike Bostock example here: http://bl.ocks.org/mbostock/1846692 | |
// SCALES | |
var quantize = d3.scale.quantize() | |
.domain([0.85, 1.15]) | |
.range(['#1a9641', '#a6d96a', '#bababa', '#fdae61', '#d7191c']); | |
var margin = {top: 20, right: 20, bottom: 30, left: 50}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom, | |
bleed = 100; | |
var pack = d3.layout.pack() | |
.sort(d3.descending) | |
.size([700, 500]) | |
.padding(.5) | |
.value(function(d) { return d.counts; }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
// LEGEND | |
svg.append("g") | |
.attr("class", "legendQuant") | |
.attr("transform", "translate(20,20)"); | |
var legend = d3.legend.color() | |
.labelFormat(d3.format(".2f")) | |
.useClass(false) | |
.scale(quantize) | |
.labels(['Most Positive', 'Positive', 'Neutral', 'Negative', 'Most Negative']) | |
.labelAlign('left'); | |
svg.select(".legendQuant") | |
.call(legend); | |
// TOOL-TIP | |
var tip = d3.tip() | |
.attr('class', 'd3-tip') | |
.offset([-10, 0]) | |
.html(function(d) { | |
return "<div><span>Word:</span> <span style='color:white'>" + d.word + "</span></div>" + | |
"<div><span>Negativity:</span> <span style='color:white'>" + d3.round(d.negativity, 2) + "</span></div>" + | |
"<div><span>Frequency:</span> <span style='color:white'>" + d.counts + "</span></div>"; | |
}) | |
svg.call(tip); | |
d3.csv("data.csv", function(error, data) { | |
if (error) throw error; | |
data.forEach(function(d){ | |
d.counts = + d.counts; | |
d.negativity = + d.negativity; | |
return d | |
}) | |
// Convert the data into a format copasetic for the pack layout | |
data = { children: data }; | |
// Create the selection | |
var node = svg.selectAll(".node") | |
.data(pack.nodes(data).filter(function(d) { return !d.children; })) | |
.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) | |
.on('mouseover', tip.show) | |
.on('mouseout', tip.hide); | |
// Append the circles | |
node.append("circle") | |
.attr("r", function(d) { return d.r; }) | |
.style("fill", function(d) {return quantize(d.negativity); }); | |
// Append the text | |
node.append("text") | |
.text(function(d) { return d.word; }) | |
.style("font-size", function(d) { return Math.min(2 * d.r, (2 * d.r - 8) / this.getComputedTextLength() * 10) + "px"; }) | |
.attr("dy", ".35em"); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment