![]() ![]() Height = px ( 30 ) ) } ) %>% cols_label ( Locations = cells_body ( vars ( headshot_href ) ), RK = as.integer ( RK ) ) %>% select ( RK, name, headshot_href, qbr_total, qb_plays, pass, run ) tab_function % gt ( ) %>% text_transform ( Tab_data % mutate (RK = rank ( desc ( qbr_total ) ), That being said, I think it’s totally fine to use this a graphic, it’s attractive, people seem to enjoy them, and everyone has the free will to make their own graph/table decisions!īelow is an example of a table that occupies roughly the same space, tells the same story, uses the same headshots, but also adds more data in QB run vs pass EPA splits along with total plays. Now sure, we’re showing a shape of the graphic, but really this is a way to show how far ahead (or behind) one player is behind another which is comparing individual values. Graph: Used to display the relationship among whole sets of values and their overall shape. Tables: Display used to look up and compare individual values. So a slight hot-take is that since we’re showing values that we’re inherently asking people to look up and compare individual values (ie find your QB of interest vs the field), this should be a table! Latest version of ggtext can be installed via remotes::install_github("wilkelab/ggtext"). I’m fine with these tradeoffs especially as the newer version is fast, and you don’t have to worry about the scaling. Can’t adjust size in ggplot - has to be done ahead of time w/ HTML syntax in our custom function.The latest version ( ggtext_0.) from GitHub does “draw” in a few seconds though!.It WAS verrrrrrry slow to draw in the RStudio plot-viewer, like on the order of a few minutes with 33 embedded images, however it would still save to png in a few seconds.OK wow, so why not just use ggtext all the time!? Height = 10, width = 10 * asp_ratio, dpi = "retina" ) toc ( ) # add element_markdown to # this will parse the labels to add img # we're also decreasing the margin so that the logos/heads are close # to the columnsĪ = element_markdown (margin = margin (t = - 25, unit = "pt" ) ) ) # axis_plot ggsave ( "qbr-axis-img.png", axis_plot, Width = 0.4 ) + scale_color_identity (aesthetics = c ( "fill", "color" ) ) + geom_hline (yintercept = 0, color = "black", size = 1 ) + theme_minimal ( ) + scale_y_continuous (breaks = scales :: pretty_breaks (n = 10 ) ) + labs (x = NULL,Ī = element_text (size = 16, face = "bold" ) ) + theme ( Rank = as.integer ( rank ) ) %>% ggplot ( ) + geom_col ( aes ( # CHANGE IS HERE # apply label to x axis labels Tic ( ) axis_plot % mutate (label = link_to_img ( headshot_href ), Credit to Emil Hvitfeldt for the idea of using an img tag and the function we’re adapting to embed images. Note that again, while this looks like a HTML call it works anywhere you want to use ggplot2. Thus, to achieve our goal of embedding images, we can create an img HTML tag to embed an image rather than just format text. In short, ggtext provides a limited subset of markdown/ HTML/ CSS syntax as an interface to changing text in ggplot2. The ggtext site has all the capabilities and function details. The overall purpose of ggtext is to provide “improved text rendering support for ggplot2”. Here ggtext::geom_richtext() handles the proper scaling of the image without really any intervention from us! While geom_richtext() is very useful we’re sort of using it out of its normal context. However, there’s an even easier way thanks to ggtext! While this may seem like a bit of work, it’s a good habit to think explicitly about what size or ratio you want to save your plots out as (it can inform how big to make your text amongst other things). ![]() Width = 0.4 ) + scale_color_identity (aesthetics = c ( "fill", "color" ) ) + geom_vline (xintercept = 0, color = "black", size = 1 ) + theme_minimal ( ) + scale_x_continuous (breaks = scales :: pretty_breaks (n = 10 ) ) + labs (x = "\nQBR",Ī = element_text (size = 16, face = "bold" ),Ī = element_text (margin = margin (r = - 25, unit = "pt" ) ), X = qbr_total, y = fct_reorder ( name, qbr_total ), Side_plot % mutate (label = link_to_img ( headshot_href ), Plot.caption = element_markdown (size = 12 ),Īxis.text = element_text (size = 14, face = "bold" ),Ī = element_text (size = 16, face = "bold" ) ) Plot.subtitle = element_text (size = 16 ), Plot.title = element_text (face = "bold", size = 20 ), ![]() Width = 0.4 ) + scale_color_identity (aesthetics = c ( "fill", "color" ) ) + geom_hline (yintercept = 0, color = "black", size = 1 ) + theme_minimal ( ) + scale_x_continuous (breaks = c ( 1, seq ( 5, 30, by = 5 ) ), limits = c ( 0.5, 34 ) ) + scale_y_continuous (breaks = scales :: pretty_breaks (n = 10 ) ) + labs (x = NULL,Ĭaption = "**Data:** espnscrapeR | **Plot:** ) + theme ( ![]() Rank = as.integer ( rank ) ) %>% ggplot ( ) + geom_col ( aes (įill = team_color, color = team_alt_color ), Basic_plot % mutate (label = link_to_img ( headshot_href ), ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |