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: {
domain: ['Real', 'Kid', 'Hollywood'],
padding:0.2,
tickFormat: d=> ''},
marks: [
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})),
Plot.dot(monsters,
Plot.dodgeY(
{x: "average_rating", anchor: 'middle', fill: 'monster_type', r:4,
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}}
})),
Plot.ruleX(monsters, Plot.groupZ({x: 'mean'}, {x: "average_rating", z: "monster_type", strokeWidth: 2, strokeDasharray: [0,1,1]})),
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}))
]
})