Published
Edited
Mar 31, 2019
Insert cell
Insert cell
Insert cell
Insert cell
// Load a file locally
viewof text = html`<input type=file * ">`
Insert cell
Insert cell
Insert cell
Insert cell
location = z.unique(z.getCol("location",tweetsDF))//get unique location names

Insert cell
//get frequency of each unique location names
tweetsDF2 = z.gbCount("tweet_id", z.groupBy(d=>d.location, tweetsDF))
Insert cell
//sort tweetsDF2 by count
tweetsDFsort = z.sort((a, b) => b.count - a.count, tweetsDF2)
Insert cell
//Create a new location column that replaces "Boston, MA", "Boston", "Boston, Massachusetts" with "Boston, MA"
locationClean = {
let grouping = [];
let locationOriginal = z.getCol("location", tweetsDF);
for (let key in Object.keys(tweetsDF)){
let row = {};
if (locationOriginal[key] == "Boston"){
row.location2 = "Boston, MA";
} else if (locationOriginal[key] == "Boston, Massachusetts"){
row.location2 = "Boston, MA";
} else if (locationOriginal[key] == "Boston, Massachusetts "){
row.location2 = "Boston, MA";
} else if (locationOriginal[key] == "boston"){
row.location2 = "Boston, MA";
} else{
row.location2 = locationOriginal[key];
}
grouping.push(row);
}
return grouping;
}
Insert cell
//add column back
tweetDF3 = z.addCol("UserLocation", z.getCol("location2", locationClean),tweetsDF)
Insert cell
//Bar chart of user provided location:
viewof view_histogram2 = embed({
data: {values: tweetDF3},
mark: "bar",
encoding: {
x: {bin: false, field: "UserLocation", type: "nominal"},
y: {aggregate: "count", type: "quantitative"}
}
})
Insert cell
Insert cell
// scatterplot
vegalite({
data: {values: tweetDF3},
mark: "point",
encoding: {
x: {field: "lat", type: "quantitative",
scale: {domain:[42.2,42.6]},
title: "latitude"}, // identify the x field as latitude
y: {field: "lon", type: "quantitative",
scale: {domain:[-71.5,-70.5]},
title: "longtitude"} // identify the y field as longtitude
}
})

Insert cell
Insert cell
// Load a file locally
viewof hashtag_text = html`<input type=file * ">`
Insert cell
Insert cell
Insert cell
Insert cell
// your ciode here
Insert cell
Insert cell
// Get Number of Hashtags in each tweet
hashtagcount ={
let grouping = [];
let hashtags = z.getCol("hashtags", tweets_mig);
for(let key in Object.keys(tweets_mig)){
let row = {};
row.hashtagCount = hashtags[key].length;
grouping.push(row);
}
return grouping;
}
Insert cell
Insert cell
Insert cell
//create a scatter plot
viewof migration_scatterplot= embed({
data: {values: tweets_mig_new},
mark: "point",
encoding: {
x: {field: "lat", type: "quantitative",
title: "Latitude"
},
y: {field: "lon", type: "quantitative",
title: "Longtitude"
},
color: {field: "Number of Hashtag", type: "quantitative"}
}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more