Created
July 3, 2019 06:38
-
-
Save adxrgh/590c792ca9d622547f93411aab67849c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ratings <- list("G", "NC-17", "PG", "PG-13", "R") | |
genres <- | |
list("Action", "Adventure", "Black Comedy", "Comedy", "Concert/Performance", | |
"Documentary", "Drama", "Horror", "Musical", "Romantic Comedy", | |
"Thriller/Suspense", "Western") | |
base <- | |
alt$Chart(vega_data$movies$url, width = 200, height = 200)$ | |
mark_point(filled = TRUE)$ | |
transform_calculate( | |
Rounded_IMDB_Rating = "floor(datum.IMDB_Rating)", | |
Hundred_Million_Production = "datum.Production_Budget > 100000000.0 ? 100 : 10", | |
Release_Year = "year(datum.Release_Date)" | |
)$transform_filter( | |
"datum.IMDB_Rating > 0" | |
)$transform_filter( | |
alt$FieldOneOfPredicate(field="MPAA_Rating", oneOf=ratings) | |
)$encode( | |
x = alt$X( | |
"Worldwide_Gross:Q", | |
scale = alt$Scale(domain=c(100000,10**9), clamp = TRUE) | |
), | |
y = "IMDB_Rating:Q", | |
tooltip = "Title:N" | |
) | |
# A slider filter | |
year_slider <- alt$binding_range(min = 1969, max = 2018, step = 1) | |
slider_selection <- | |
alt$selection_single( | |
bind = year_slider, | |
fields = list("Release_Year"), | |
name = "Release Year_" | |
) | |
filter_year <- base$ | |
add_selection(slider_selection)$ | |
transform_filter(slider_selection)$ | |
properties(title = "Slider Filtering") | |
# A dropdown filter | |
genre_dropdown <- alt$binding_select(options = genres) | |
genre_select <- | |
alt$selection_single( | |
fields = list("Major_Genre"), | |
bind = genre_dropdown, | |
name = "Genre" | |
) | |
filter_genres <- | |
base$ | |
add_selection(genre_select)$ | |
transform_filter(genre_select)$ | |
properties(title="Dropdown Filtering") | |
#color changing marks | |
rating_radio <- alt$binding_radio(options=ratings) | |
rating_select <- | |
alt$selection_single( | |
fields = list("MPAA_Rating"), | |
bind = rating_radio, | |
name = "Rating" | |
) | |
rating_color_condition <- | |
alt$condition( | |
rating_select, | |
alt$Color("MPAA_Rating:N", legend = NULL), | |
alt$value("lightgray") | |
) | |
highlight_ratings <- | |
base$ | |
add_selection(rating_select)$ | |
encode( | |
color = rating_color_condition | |
)$ | |
properties(title = "Radio Button Highlighting") | |
# Boolean selection for format changes | |
input_checkbox <- alt$binding_checkbox() | |
checkbox_selection <- | |
alt$selection_single(bind = input_checkbox, name = "Big Budget Films") | |
size_checkbox_condition <- | |
alt$condition( | |
checkbox_selection, | |
alt$SizeValue(25), | |
alt$Size("Hundred_Million_Production:Q") | |
) | |
budget_sizing <- | |
base$ | |
add_selection(checkbox_selection)$ | |
encode( | |
size = size_checkbox_condition)$ | |
properties(title = "Checkbox Formatting") | |
(filter_year | filter_genres) & (highlight_ratings | budget_sizing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment