Using visualization to support query building.
Reading, Recording, Notebook, Rmarkdown
{const selection = vl.selectSingle('Select') // name the selection 'Select'
.fields('Major_Genre') // limit selection to the Major_Genre field
.init({Major_Genre: genres[0]}) // use first genre entry as initial value
.bind(vl.menu(genres)); // bind to a menu of unique genre values
// scatter plot, modify opacity based on genre selection
return vl.markCircle()
.data(movies)
.select(selection)
.encode(
.x().fieldQ('Rotten_Tomatoes_Rating'),
vl.y().fieldQ('IMDB_Rating'),
vl.tooltip().fieldN('Title'),
vl.opacity().if(selection, vl.value(0.75)).value(0.05)
vl
).render();
}
robservable("@krisrs1128/week-3-2", include = 6, height = 325)
menu
bindings, there are checkbox
, radio
, and slider
inputs. If you revisit the gapminder visualization in Lecture 1-3, you will see that the interaction was accomplished by binding a selection to a slider
input.selection
object in the first few lines.
{ // single-value selection over [Major_Genre, MPAA_Rating] pairs
// use specific hard-wired values as the initial selected values
const selection = vl.selectSingle('Select')
.fields('Major_Genre', 'MPAA_Rating')
.init({Major_Genre: 'Drama', MPAA_Rating: 'R'})
.bind({Major_Genre: vl.menu(genres), MPAA_Rating: vl.radio(mpaa)});
// scatterplot, modify opacity based on selection
return vl.markCircle()
.data(movies)
.select(selection)
.encode(
.x().fieldQ('Rotten_Tomatoes_Rating'),
vl.y().fieldQ('IMDB_Rating'),
vl.tooltip().fieldN('Title'),
vl.opacity().if(selection, vl.value(0.75)).value(0.05)
vl
).render();
}
robservable("@krisrs1128/week-3-2", include = 7, height = 335)
filter
elements or select
attributes, we can design interactive visual equivalents.
{const brush = vl.selectInterval()
.encodings('x'); // limit selection to x-axis (year) values
// dynamic query histogram
const years = vl.markBar()
.data(movies)
.select(brush)
.encode(
.x().year('Release_Date').title('Films by Release Year'),
vl.y().count().title(null)
vl
).width(500)
.height(40);
// ratings scatter plot
const ratings = vl.markCircle()
.data(movies)
.encode(
.x().fieldQ('Rotten_Tomatoes_Rating'),
vl.y().fieldQ('IMDB_Rating'),
vl.tooltip().fieldN('Title'),
vl.opacity().if(brush, vl.value(0.75)).value(0.05)
vl
).width(500)
.height(350);
return vl.vconcat(years, ratings).render();
}
robservable("@krisrs1128/week-3-2", include = 8, height = 390)