class: center, middle, inverse, title-slide .title[ # ggtrace_highjack_return ] .subtitle[ ## A flipbook treatment ] --- ## Usage ```r ggtrace_highjack_return( x, # A ggplot object method, # A function or a ggproto method. The ggproto method may be specified # using any of the following forms: ggproto$method, namespace::ggproto$method, # namespace:::ggproto$method cond = 1L, # When the return value should be replaced. Defaults to 1L. value = quote(returnValue()), # What the method should return instead. Defaults to quote(returnValue()). draw = TRUE # Whether to draw the modified graphical output from evaluating x. # Defaults to TRUE. ) ``` --- count: false # base plot to highjack .panel1-start-1[ ```r library(tidyverse) library(ggtrace) p1 <- ggplot(diamonds, aes(cut)) + geom_bar(aes(fill = cut)) + facet_wrap(~ clarity, ncol = 2) p1 ``` ] .panel2-start-1[ ![](highjack-return_files/figure-html/start_1_01_output-1.png)<!-- --> ] <style> .panel1-start-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # first panel to zero .panel1-start1-1[ ```r ggtrace_highjack_return( x = p1, * method = Stat$compute_panel, * value = quote({ * returnValue() %>% * mutate(count = 0) }) ) ``` ] .panel2-start1-1[ ![](highjack-return_files/figure-html/start1_1_01_output-1.png)<!-- --> ] <style> .panel1-start1-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start1-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start1-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # first panel times 20 .panel1-start12-1[ ```r ggtrace_highjack_return( x = p1, method = Stat$compute_panel, value = quote({ returnValue() %>% * mutate(count = count*20) }) ) ``` ] .panel2-start12-1[ ![](highjack-return_files/figure-html/start12_1_01_output-1.png)<!-- --> ] <style> .panel1-start12-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start12-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start12-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # back to original .panel1-start11-1[ ```r ggtrace_highjack_return( x = p1, method = Stat$compute_panel, value = quote({ returnValue() %>% * mutate(count = count) }) ) ``` ] .panel2-start11-1[ ![](highjack-return_files/figure-html/start11_1_01_output-1.png)<!-- --> ] <style> .panel1-start11-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start11-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start11-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # mix up 4th panel x positions? .panel1-start2-1[ ```r ggtrace_highjack_return( x = p1, method = Stat$compute_panel, * cond = quote(data$PANEL[1] == 4), value = quote({ returnValue() %>% * mutate(x = sample(x)) }) ) ``` ] .panel2-start2-1[ ![](highjack-return_files/figure-html/start2_1_01_output-1.png)<!-- --> ] <style> .panel1-start2-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start2-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start2-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # mix up 4th panel counts? .panel1-start27-1[ ```r ggtrace_highjack_return( x = p1, method = Stat$compute_panel, * cond = quote(data$PANEL[1] == 4), value = quote({ returnValue() %>% * mutate(count = sample(count)) }) ) ``` ] .panel2-start27-1[ ![](highjack-return_files/figure-html/start27_1_01_output-1.png)<!-- --> ] <style> .panel1-start27-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start27-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start27-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # back to original .panel1-start111-1[ ```r ggtrace_highjack_return( x = p1, method = Stat$compute_panel, cond = quote(data$PANEL[1] == 4), value = quote({ returnValue() %>% * mutate(count = count) }) ) ``` ] .panel2-start111-1[ ![](highjack-return_files/figure-html/start111_1_01_output-1.png)<!-- --> ] <style> .panel1-start111-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start111-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start111-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false # very special highlighting for panel 4 .panel1-start3-1[ ```r ggtrace_highjack_return( x = p1, * method = GeomBar$draw_panel, cond = quote(data$PANEL[1] == 4), value = quote({ * editGrob( returnValue(), * gp = gpar( * col = "black", * alpha = seq(0.2, 1, * length.out = * nrow(data) ))) }) ) ``` ] .panel2-start3-1[ ![](highjack-return_files/figure-html/start3_1_01_output-1.png)<!-- --> ] <style> .panel1-start3-1 { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-start3-1 { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-start3-1 { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style>