Published
Edited
Oct 7, 2021
2 forks
7 stars
Insert cell
Insert cell
Insert cell
deviceAnalytics = FileAttachment("device-analytics.csv").csv()
Insert cell
Inputs.table(deviceAnalytics)
Insert cell
Insert cell
deviceAnalytics[0]
Insert cell
Insert cell
devices = deviceAnalytics.map(
(d) => d // TODO replace this
)
Insert cell
Insert cell
Insert cell
// Note: when we only have a single type of mark, we can use the syntax
// Plot.markType(..).plot(options), which is equivalent to
// Plot.plot({marks: [Plot.markType(...)], ...options})

// Draw vertical bars:
Plot.barY(
devices, // based on this data
// group the data into categories on the X axis:
Plot.groupX(
{ y: "count" }, //outputs: specify which aggregation calculation to perform ("count") the which channel it should be shown on (y)
{ x: "Device" } //inputs: specify what should be the input for the calculation ("Device"), and what channel it should be shown on (x)
)
).plot({
marginLeft: 50 // make space for the labels on Y axis
})
Insert cell
Insert cell
Insert cell
// TODO your code here
Insert cell
Insert cell
Insert cell
Insert cell
Plot.dot(devices, {
// TODO your code here
}).plot({
// some default layout tweaks (feel free to change):
width,
height: width * 0.5,
x: { grid: true, domain: [0, 4200] },
y: { grid: true, domain: [0, 2600] },
opacity: { type: "log" }
})
Insert cell
Insert cell
Insert cell
Insert cell
// TODO copy your dot plot code here
// then add facets!
Insert cell
Insert cell
Insert cell
devicesFinished = deviceAnalytics.map((d) => {
// This is one solution; yours may look a bit different!
let [Width, Height] = d.Resolution.split("x");
return {
Device: d.Device,
Resolution: d.Resolution,
Width: +Width,
Height: +Height,
Users: +d.Users,
Sessions: +d.Sessions
};
})
Insert cell
finishedDevices = Plot.barY(
devicesFinished,
Plot.groupX(
{ y: "sum", title: "sum" },
{ x: "Device", y: "Users", fill: "Device", title: "Users" }
)
).plot({
marginLeft: 50
})
Insert cell
// One possible solution; yours may differ!
finishedResolutions = Plot.dot(devicesFinished, {
x: "Width",
y: "Height",
fill: "Device",
fillOpacity: "Sessions",
r: ({ Sessions }) => Math.log(Sessions),
title: ({ Resolution, Sessions }) => [Resolution, Sessions].join(": ")
}).plot({
width,
height: width * 0.5,
x: { grid: true, domain: [0, 4200] },
y: { grid: true, domain: [0, 2600] },
opacity: { type: "log" }
})
Insert cell
finishedResolutionsByDevice = Plot.dot(devicesFinished, {
x: "Width",
y: "Height",
fill: "Device",
fillOpacity: "Sessions",
r: ({ Sessions }) => Math.log(Sessions),
title: ({ Resolution, Sessions }) => [Resolution, Sessions].join(": ")
}).plot({
width,
height: width * 0.5,
x: { grid: true, domain: [0, 5000] },
y: { grid: true, domain: [0, 2600] },
opacity: { type: "log" },
facet: { data: devicesFinished, x: "Device" }
})
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