Published
Edited
Aug 13, 2022
1 star
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
Insert cell
pickArtist = data.filter((d,i) => i === ind)[0]
Insert cell
pivotArtist = tidy(
[pickArtist],
pivotLonger({cols: Object.keys(metrics), namesTo: "metric", valuesTo: "value"}),
filter(d => d.value)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
metrics = ({
"spotify_monthly": "Spotify Listeners",
"youtube_subscribers": "YouTube Subscribers",
"tiktok_followers": "TikTok Followers",
})
Insert cell
pivotData = tidy(
data,
pivotLonger({cols: Object.keys(metrics), namesTo: "metric", valuesTo: "value"}),
filter(d => d.value)
)
Insert cell
spotify_percentages = {
// total spotify listeners
let totalSpotify = tidy(
data,
select(["artist", "spotify_monthly"]),
summarize({perc: sum("spotify_monthly")})
)[0].perc

// percentages for each artist
return tidy(
data,
select(["artist", "spotify_monthly"]),
mutate({perc: d => d.spotify_monthly / totalSpotify * 100})
)
}
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