首页 > 解决方案 > R - 使用 ggplot + bbplot 个性化刻度轴刻度

问题描述

大家好,首先感谢您的帮助。

我正在使用 ggplot 和 bbplot 绘制关于利率数据的线图,到目前为止一切都很好,除了我希望 X 轴更详细地显示日期。理想情况下,我想要这样的图像,尽管每年显示也会这样做:在此处输入图像描述

到目前为止,我所取得的是使用以下代码的图像波纹管:

library(readxl)
cetes_14 <- read_excel("cetes.xlsx", sheet = "Hoja2")
View(cetes_14)

#Crear gráfico con ggplot y la ayuda de bbplot y scales
library(ggplot2)
library(bbplot)
library(scales)
cetes14_plot <- ggplot(cetes_14, aes(x = cetes_14$FECHA, y =cetes_14$RENDIMIENTO, colour = cetes_14$PERIODO)) +
  geom_line(size = 1) +
  scale_fill_brewer(palette="Dark2") +
  geom_hline(yintercept = 0, size = 1, colour="#333333")+
  bbc_style() +
  labs(title="Rendimiento CETES 28,91,182 y 364",
       subtitle = "2014-2020")+
  scale_y_continuous(breaks =  seq(0.0,0.09,0.01),labels = percent)

#Guardar plot y agregar fuente

finalise_plot(plot_name = cetes14_plot,
              source = "Fuente: Elaboración propia con datos Banxico")

在此处输入图像描述

我曾尝试使用 scale_x_continuous但到目前为止没有任何效果,而且我无法找到另一种解决方案。我希望你能帮助我,谢谢。

标签: rggplot2

解决方案


推荐阅读