Plot.plot({
width: width,
height: 300,
x: {
type: "log"
},
color: {
legend: true,
type: "ordinal",
domain: ["NA", "Low income", "Lower middle income", "Upper middle income", "High income"],
range: ["gray", 'red', 'orange', 'blue', 'green']
},
marks: [
Plot.dot(worldbank2010, { x: "gdp", y: "life_exp", fill: "gray", opacity: 0.2}),
Plot.dot(worldbank2010, { x: "gdp", y: "life_exp", fx: "region", fill: "income_group"}),
Plot.text(worldbank2010, Plot.select({y: "max"}, { x: "gdp", y: "life_exp", fx: "region", text: "country_name", fill: "green", dy: -5})),
Plot.text(worldbank2010, Plot.select({y: "min"}, { x: "gdp", y: "life_exp", fx: "region", text: "country_name", fill: "red", dy: -5})),
Plot.frame()
]
})