Public
Edited
Sep 19, 2023
Fork of Net Worth
Insert cell
Insert cell
example = FileAttachment("example.json").json()
Insert cell
data = example.data
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data1
X
year
Y
mean
Color
series
Size
Facet X
Facet Y
Mark
line
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Select a data source…
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
style: "overflow: visible;",
y: { grid: true },
color: {
type: "ordinal",
legend: true,
legendPosition: "right",
range: [
"#009e73",
"#ffb000",
"#dc267f",
"#648fff",
"#d55e00",
"#cc79a7",
"#0072b2",
"#f0e442",
"#785ef0",
"#fe6100"
]
},

marks: [
Plot.lineY(data1, {
x: "year",
y: "mean",
stroke: "series",
tip: true
}),
Plot.text(
data1,
Plot.selectLast({
x: "year",
y: "mean",
z: "series",
text: "series",
textAnchor: "start",
dx: 3
})
)
]
})
Insert cell
Insert cell
//compute the average of the column called mean
average = data1.reduce((total, d) => total + d.mean, 0) / data1.length
Insert cell
//set the minimum of axis=minimum of data - x*average. Adjust x
yaxisMin = Math.min(...data1.map((d) => d.mean)) -0.2 * average
Insert cell
//set the maximum of axis=maximum of data + x*average. Adjust x
yaxisMax = Math.max(...data1.map((d) => d.mean)) + 0.15 * average
Insert cell
Plot.plot({
style: "overflow: visible;",
y: { grid: true, domain: [yaxisMin, yaxisMax] }, //here add the y axis min/max

marks: [
Plot.lineY(data1, {
x: "year",
y: "mean",
stroke: "series",
tip: true
}),
Plot.text(
data1,
Plot.selectLast({
x: "year",
y: "mean",
z: "series",
text: "series",
textAnchor: "start",
dx: 5
})
)
]
})
Insert cell
Insert cell
Plot.plot({
//size
height: 543,
width: 900,
//space around
marginLeft: 100, // space to the left of the chart
marginRight: 50,
marginTop: 50,
marginBottom: 50, // space below the chart
//space within
insetTop: 0,
insetBottom: 10, // space between the x-axis and the marks
insetLeft: 20, // space between the y-axis and the marks
insetRight: 47,

x: { label: "Year " },
y: { label: "$" },
style: { fontSize: "20" }, //changes the fontsize of line label

y: { grid: true },

marks: [
Plot.axisX({ fontSize: 12 }), //fontsize of x axis marks
Plot.axisY({ fontSize: 12, label: "$" }),
Plot.lineY(data1, {
x: "year",
y: "mean",
stroke: "series",
tip: true
}),
Plot.text(
data1,
Plot.selectLast({
x: "year",
y: "mean",
z: "series",
text: "series",
textAnchor: "start",
dx: 5
})
)
]
})
Insert cell
Plot.plot({
x: {
label: "Year ",
tickFormat: d3.format("$.2f"),

ticks: 2,
line: true,
nice: true
},
y: { label: "$" },
style: { fontSize: "14" },

y: { grid: true },

marks: [
Plot.axisX({ fontSize: 16 }),
Plot.axisY({ fontSize: 12, label: "$" }),
Plot.lineY(data1, {
x: "year",
y: "mean",
stroke: "series",
tip: true
}),
Plot.text(
data1,
Plot.selectLast({
x: "year",
y: "mean",
z: "series",
text: "series",
textAnchor: "start",
dx: 5
})
)
],

// Layout adjustments
marginTop: 50,
marginRight: 10,
marginBottom: 50,
marginLeft: 80
})
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