Published
Edited
Apr 27, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
promoters_top10
Insert cell
detractors_top10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof communities = vl.markBar()
.data(community_data)
.encode(
vl.color().fieldN('community_type'),
vl.x().fieldN('community').title("Community").axis({titleFontSize:12}),
vl.y().fieldQ('user_count').title("Number of Users").axis({titleFontSize:12}), //.sort(vl.sum('cases').order('descending'),
vl.tooltip(['user_count']))
.height(height/3)
.width(width/3)
.padding("20")
.render()
Insert cell
Insert cell
viewof account_status = vl.markBar({tooltip: {"content": "data"}, size:5})
.data(community_data)
.encode(
vl.color().fieldN('community_type'),
vl.x().fieldQ(
vl.repeat("repeat")
).axis({grid: false, titleFontSize:"13", labelFontSize: "12"}),
vl.y().fieldN('community').axis({grid: false, title: false, labelFontSize: "12"}),
//vl.y().fieldN('community_type').axis({grid: false, title: "Community Type", titleFontSize:"12", labelFontSize: "12"}),
//vl.tooltip().fieldT("date") //([vl.fieldT("date"), "total_cases", "total_hospitalizations"])
//vl.color( {"value": "teal"})
)
.height(height/9)
.width(width/4)
.repeat([
"active_users_p",
"deleted_users_p",
"suspended_p"
])
.columns(1)
//.title({text:"Total Cases, Hospitalizations, and Deaths in VA over Time", fontSize:"30", offset:"30"})
.padding("20")
.render()
Insert cell
Insert cell
viewof account_status_percent = vl.markBar({tooltip: {"content": "data"}, size:5})
.data(user_status_data)
.transform(
vl.groupby('community_type','user_status').aggregate(vl.average('percentage').as('total')))
.encode(
vl.color().fieldN('user_status'),
vl.x().fieldQ('total'),
vl.y().fieldN('community_type'
//vl.repeat("repeat")
)
)
// .repeat(['detractors',
// 'promoters'])
// .columns(1)
.padding("20")
.render()
Insert cell
viewof account_status_1 = vl.markBar({tooltip: {"content": "data"}, size:5})
.data(user_status_data)
.transform(
vl.groupby('user_status').aggregate(vl.average('percentage').as('total')))
.encode(
vl.x().fieldQ('total'),
vl.y().fieldN('user_status')
)
.padding("20")
.render()
Insert cell
viewof account_status_new_repeat = vl.markBar({tooltip: {"content": "data"}, size:5})
.data(user_status_data)
.transform(
vl.groupby('community_type','user_status').aggregate(vl.average('percentage').as('total_percentage')))
.encode(
vl.color().fieldN('user_status'),
vl.x().fieldQ('total_percentage'),
vl.y().fieldN('community_type'),
vl.y().fieldN(
vl.repeat("repeat")
)
)
.repeat(['detractors',
'promoters'])
.columns(1)
.padding("20")
.render()
Insert cell
viewof account_status_dp = vl.markBar({tooltip: {"content": "data"}, size:5})
.data(community_data)
.transform(
vl.groupby('community_type').aggregate(vl.sum('user_count').as('Users'), vl.sum('active_users').as('Active'),vl.sum('deleted_users').as('Deleted'),vl.sum('suspended_users').as('Suspended') ),
vl.calculate("datum.Active/datum.Users * 100").as("Percentage of Active Users"),
vl.calculate("datum.Deleted/datum.Users * 100").as("Percentage of Deleted Users"),
vl.calculate("datum.Suspended/datum.Users * 100").as("Percentage of Suspended Users")
)
.encode(
vl.color().fieldN('community_type'),
vl.x().fieldQ(
vl.repeat("repeat")
).axis({grid: false, titleFontSize:"13", labelFontSize: "12"}),
vl.y().fieldN('community_type').axis({grid: false, title: false, labelFontSize: "12"}),
//vl.y().fieldN('community_type').axis({grid: false, title: "Community Type", titleFontSize:"12", labelFontSize: "12"}),
//vl.tooltip().fieldT("date") //([vl.fieldT("date"), "total_cases", "total_hospitalizations"])
//vl.color( {"value": "teal"})
)
.width(width/5)
.repeat([
"Percentage of Active Users",
"Percentage of Deleted Users",
"Percentage of Suspended Users"
])
.columns(1)
//.title({text:"Total Cases, Hospitalizations, and Deaths in VA over Time", fontSize:"30", offset:"30"})
.padding("20")
.render()
Insert cell
viewof account_status_percentage = vl.markBar({tooltip: {"content": "data"}, size:20})
.data(user_status_data)
.params('select')
.transform(
vl.groupby('community_type','user_status').aggregate(vl.average('percentage').as('total')))
.encode(
vl.color().fieldN('user_status'),
vl.x().fieldQ('total'),
vl.y().fieldN('community_type'))
.height(height/6)
.width(width/2)
.padding("20")
.render()
Insert cell
viewof account_status1 = vl.markBar({tooltip: {"content": "data"}, size:15})
.data(user_status_data)
.transform(
vl.groupby('community_type', 'user_status', 'community').aggregate(vl.average('percentage').as('total_p')),
vl.calculate('datum.total_p/5').as('total')
)
.encode(
vl.color().fieldN('community_type'), //.scale( {"range": ["#7aacb3", "#006666"]}),
vl.x().fieldQ('total').title("Number of Users").axis({titleFontSize:12}),
vl.y().fieldN('user_status').title("Status").axis({titleFontSize:12}),
)
.title({text: "Account Status of Users", subtitle: "Suspended and deleted users were found to be mostly promoters" , color: "#ad6d9c", subtitleColor: "#856a7e", fontWeight: "bold", fontSize: "15"})
.height(0.08*height)
.width(width/2.7)
.padding("20")
.render()

Insert cell
Insert cell
viewof tweets = vl.markCircle({size: 50})
.data(tweet_data)
.params(vl.selectInterval().bind("scales"))
.encode(
vl.color().fieldN('community_type'),
vl.x().fieldQ("RTs").axis({ title: "Number of Retweets", titleFontSize:"12", labelFontSize: "15", tickCount:15}).scale({"domain": [0,30000]}), //.scale({"type": "log"}) // .timeUnit('utcmonthdate'),
vl.y().fieldQ("QTs").axis({title: "Number of Quote Tweets", titleFontSize:"12", labelFontSize: "15"}).scale({"domain": [0,6000]}),
vl.tooltip([vl.fieldN("tweet_id"), "RTs", "QTs"]), //.fieldQ("cases")
//vl.color( {"value": "teal"})
)
//.title( {text:"Total Cases Vs. Deaths Reported per Each Locality in VA", fontSize:"30"})
.height(height/3)
.width(width/3)
.padding("20")
//.background("#f5f7ff")
.render()
Insert cell
Insert cell
viewof users = vl.markPoint({size: 40})
.data(user_data)
.params(vl.selectInterval().bind("scales"))
.encode(
vl.color().fieldN('community_type'),
vl.x().fieldQ("RTs").axis({title: "Number of Retweets", titleFontSize:"12", labelFontSize: "15", tickCount:15}).scale({"domain": [0,30000]}), //.scale({"type": "log"}) // .timeUnit('utcmonthdate'),
vl.y().fieldQ("QTs").axis({title: "Number of Quote Tweets", titleFontSize:"12", labelFontSize: "15"}).scale({"domain": [0,6000]}),
vl.tooltip([vl.fieldN("user_id"), "RTs", "QTs"]), //.fieldQ("cases")
vl.href().fieldN('user_url')
//vl.color( {"value": "teal"})
)
//.title( {text:"Total Cases Vs. Deaths Reported per Each Locality in VA", fontSize:"30"})
.height(height/3)
.width(width/3)
.padding("20")
//.background("#f5f7ff")
.render()
Insert cell
Insert cell
viewof urls_detractors1 = vl.layer(
vl.markBar()
.encode(
vl.color().value('#66b2b2'),
vl.x().fieldQ('RTs_community0').title("Number of Retweets"),
vl.y().fieldN('domain').axis(null).title("Top 10 Domains").sort(vl.fieldQ('RTs_community0').order('descending')),
vl.tooltip(['RTs_community0'])
),
vl.markText({align: 'left', x: 1}).encode(vl.text().fieldN('domain'))
)
.data(detractors_top10)
.height(height/3)
.width(width/3)
.padding("20")
//.background("#f5f7ff")
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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