Created
October 16, 2025 19:05
-
-
Save DATAUNIRIO/a363f0399e813d3f1fbc63bb8ec7500d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # https://rfortherestofus.com/2024/01/speedometer | |
| library(tidyverse) | |
| library(ggplot2) | |
| #Metas Alcançadas | |
| #7.84% das metas estão alcançadas | |
| percentage_done = 0.078 | |
| percentual_feito = scales::comma(percentage_done, accuracy = 0.001, big.mark = "." , decimal.mark = ",") | |
| fake_dat = tibble( | |
| part = c("Complete", "Incomplete"), | |
| percentage = c(percentage_done, 1 - percentage_done)) | |
| fake_dat$percentage = scales::comma(fake_dat$percentage, big.mark = "." , decimal.mark = ",") | |
| #---------------------------------------------------------- | |
| # progress_plot | |
| #---------------------------------------------------------- | |
| fake_dat %>% | |
| ggplot(aes(x = "", y = percentage, fill = part)) + | |
| geom_col(width = .25,position = position_stack(reverse = TRUE)) + | |
| scale_fill_manual( | |
| #values = c("Complete" = "#009E73", "Incomplete" = "grey80") | |
| values = c("Complete" = "steelblue", "Incomplete" = "tomato") | |
| ) + | |
| coord_flip() + | |
| theme_void() + | |
| theme( | |
| legend.position = "none", | |
| plot.title = element_text( | |
| family = "Source Sans Pro", size = 28, face = "bold" | |
| ), | |
| plot.subtitle = element_text(family = "Source Sans Pro", size = 18) | |
| ) + | |
| annotate( | |
| "text", | |
| x = 0.95, | |
| y = 0.5, | |
| label = glue::glue("{scales::percent(percentage_done)} completo"), | |
| size = 12, | |
| family = "Source Sans Pro", | |
| fontface = "bold", | |
| color = "black", | |
| vjust = 0 | |
| )+ | |
| labs( | |
| title = "Metas Alcançadas", | |
| subtitle = paste0(percentual_feito ," das metas estão alcançadas."), | |
| y='', | |
| ) | |
| #---------------------------------------------------------- | |
| # gauge_plot | |
| #---------------------------------------------------------- | |
| percentage_done = 0.95 | |
| fake_dat = tibble( | |
| part = c("Complete", "Incomplete"), | |
| percentage = c(percentage_done, 1 - percentage_done), | |
| start = lag(percentage, default = 0) * pi, | |
| end = start + percentage * pi | |
| ) | |
| fake_dat | |
| library(ggforce) | |
| gauge_plot <- fake_dat |> | |
| ggplot() + | |
| geom_arc_bar( | |
| aes( | |
| x0 = 1, | |
| y0 = 1, | |
| fill = part, | |
| start = start - pi / 2, | |
| end = end - pi / 2, | |
| r0 = 0.75, | |
| r = 1 | |
| ) | |
| ) + | |
| coord_fixed() | |
| gauge_plot | |
| labeled_gauge_plot <- gauge_plot + | |
| annotate( | |
| "text", | |
| x = 1, | |
| y = 1, | |
| label = glue::glue("{percentage_done * 100}% complete"), | |
| size = 16, | |
| family = "Source Sans Pro", | |
| fontface = "bold", | |
| color = "#009E73", | |
| vjust = 0 | |
| ) + | |
| labs( | |
| title = "This is a gauge plot", | |
| subtitle = "It was created in ggplot and shows you how much of your goal\nyou have already achieved." | |
| ) | |
| labeled_gauge_plot | |
| themed_gauge_plot <- labeled_gauge_plot + | |
| theme_void() + | |
| theme( | |
| legend.position = "none", | |
| plot.title = element_text( | |
| family = "Source Sans Pro", size = 28, face = "bold" | |
| ), | |
| plot.subtitle = element_text(family = "Source Sans Pro", size = 18) | |
| ) | |
| themed_gauge_plot | |
| themed_gauge_plot + | |
| scale_fill_manual( | |
| values = c("Complete" = "#009E73", "Incomplete" = "grey80") | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment