Created
September 14, 2024 14:52
-
-
Save jtrecenti/c06bf4d87e590b76e63cf7c1bba71085 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
install.packages("yfR") | |
da <- yfR::yf_get( | |
"AMER3.SA", | |
first_date = "2024-05-15", | |
last_date = "2024-06-04" | |
) |> | |
dplyr::mutate( | |
price_close = price_close / 100, | |
batom = preco_batom / price_close | |
) | |
preco_batom <- 3.98 | |
da |> | |
ggplot2::ggplot( | |
ggplot2::aes(x = ref_date, y = price_close) | |
) + | |
ggplot2::geom_line( | |
linewidth = 2, | |
color = "red", | |
linetype = "dashed" | |
) + | |
ggplot2::geom_line( | |
ggplot2::aes(x = ref_date, y = batom/20), | |
linewidth = 2, | |
color = "#b5651d" | |
) + | |
ggplot2::geom_line( | |
ggplot2::aes(x = ref_date, y = batom/20), | |
linewidth = 2, | |
color = "red", | |
linetype = "dashed" | |
) + | |
ggplot2::scale_y_continuous( | |
sec.axis = ggplot2::sec_axis( | |
~ preco_batom / ., | |
name = "Preço Baton / AMER3\nCompre baton", | |
breaks = c(7.5, 8, 9, 10, 11, 12), | |
labels = paste0(rev(c(7.5, 8, 9, 10, 11, 12)), "x") | |
), | |
labels = scales::dollar_format(prefix = "R$", big.mark = ".", decimal.mark = ",") | |
) + | |
ggplot2::theme_minimal(18) + | |
ggimage::geom_image( | |
ggplot2::aes(y = batom/20), | |
image = "/Users/julio/Downloads/baton.png", | |
data = tail(da, 1), | |
size = .4, | |
nudge_x = 3 | |
) + | |
ggimage::geom_image( | |
ggplot2::aes(y = price_close), | |
image = "/Users/julio/Downloads/amer3.png", | |
data = head(da, 1), | |
size = .2, | |
nudge_x = -1.5 | |
) + | |
ggplot2::coord_cartesian( | |
clip = "off", | |
xlim = c(as.Date("2024-05-13"), as.Date("2024-06-09")), | |
ylim = c(0.35, 0.55) | |
) + | |
ggplot2::labs( | |
title = "Parece que o jogo virou, não é mesmo?", | |
subtitle = "Compre Baton: R$ 3,98", | |
caption = "Compre Baton", | |
x = "Compre Baton", | |
y = "Preço Fechamento AMER3\nCompre Baton" | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment