如何将底部图形变大?
library(quantmod)
p1 <- rnorm(4000) |> cumsum() |> xts(Sys.time()+1:4000) |> to.minutes(name = NULL) |> round(0)+100
chart_Series(p1)
add_Series(p1, on = NA)
如果无法直接使用 Quantmod,您可以考虑使用下面的 ggplot 和 patchwork。两者都可以对情节美学进行高度控制,例如使用
heights = c(1, 1)
设置高度相对比例。
library(tidyquant)
library(tidyverse)
library(quantmod)
library(patchwork)
xt <- rnorm(4000) |>
cumsum() |>
xts(Sys.time() + 1:4000) |>
to.minutes(name = NULL) |>
round(0) + 100
df <- xt |>
as_tibble(rownames = "date") |>
mutate(date = as_datetime(date))
p1 <- df |>
ggplot(aes(x = date, y = Close)) +
geom_candlestick(aes(open = Open, high = High, low = Low, close = Close)) +
scale_x_datetime(date_breaks = "15 mins", date_labels = "%b %d\n%H:%M") +
theme_bw() +
labs(x = NULL)
p2 <- df |>
ggplot(aes(x = date, y = Close)) +
geom_candlestick(aes(open = Open, high = High, low = Low, close = Close)) +
scale_x_datetime(date_breaks = "15 mins", date_labels = "%b %d\n%H:%M") +
theme_bw() +
labs(x = NULL)
p1 / p2 + plot_layout(axes = "collect", heights = c(1, 1))
创建于 2024-03-22,使用 reprex v2.1.0