Public
Edited
Oct 30, 2024
1 fork
9 stars
Insert cell
Insert cell
Plot.plot({
title: 'Real Monsters, Kid Monsters, and Hollywood Monsters',
subtitle: 'Movie ratings containing "Monster" in thte title. Scale of 1 to 10. Data from imdb.',
caption: 'Source: imdb',
height: 600,
width:800,
marginLeft: 2,
marginTop:30,
y: {tickSize:0},
x: {tickSize:0, domain: [1,10], grid: true, label: 'Avg Rating'},
color: {range: ['#AEBDF0','#86CB92','#EBCA68']},
facet: {
data: monsters,
y: 'monster_type',
label: null
},
fy: {
//use domain to adjust the order of the facet
domain: ['Real', 'Kid', 'Hollywood'],
padding:0.2,
//hack to remove facet labels, we'll replace with Plot text (there might be a better way to do this)
tickFormat: d=> ''},
marks: [
//add facet text above the chart
Plot.text(monsters, Plot.groupZ(
{text: "first"},
{text: d=> d.monster_type + ' Monsters', fontWeight: 'bold', fontSize: 14, z: "monster_type", frameAnchor: "top-left", dy: -20, dx:-2})),
Plot.text(monsters, Plot.groupZ(
{text: "first"},
{text: "monster_type_desc", fontSize: 12, fill: 'grey', z: "monster_type", frameAnchor: "top-left", dy: -5, dx:-2})),
//beeswarm chart
Plot.dot(monsters,
Plot.dodgeY(
{x: "average_rating", anchor: 'middle', fill: 'monster_type', r:4,
//adjust the tooltip with channels
channels: {
Movie: "primary_title", Year: d=> d.year.toString(), 'Number Votes': 'num_votes',
'Average Rating': "average_rating"
},
tip: {
format: {fill: false, x: false, fy: false}}
})),
//average of averages, plut as a vertical line intercept
Plot.ruleX(monsters, Plot.groupZ({x: 'mean'}, {x: "average_rating", z: "monster_type", strokeWidth: 2, strokeDasharray: [0,1,1]})),
//add vertical text alongisde the average line
Plot.text(monsters, Plot.groupZ({x: 'mean',
text: (d) => 'Avg: ' + d3.mean(d).toFixed(1)},
{text: "average_rating", x: "average_rating", z: "monster_type", fontSize: 10,
rotate: -90, dx: -7,dy: -60, fill: 'black', r: 5}))
]
})
Insert cell
Insert cell
movies
select m. *,
case
when genres LIKE '%Documentary%' then 'Real'
when genres LIKE '%Animation%' or genres LIKE '%Family%' then 'Kid'
else 'Hollywood' end as monster_type
,case
when genres LIKE '%Documentary%' then 'Documentaries'
when genres LIKE '%Animation%' or genres LIKE '%Family%' then 'Family or Animation'
else 'All other genres' end as monster_type_desc
from movies m
Insert cell
Insert cell
monster_movies.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more