【问题标题】:How do I fit my x-axis date labels into the figure?如何将我的 x 轴日期标签放入图中?
【发布时间】:2021-09-28 09:02:31
【问题描述】:

我的 x 轴使用 Lubridate 包格式化为日期。

我尝试了 xlim 和 break 的不同选项,但似乎无法让“2020”适合这个数字。

interest_exp_line <- ggplot(interest_exp_df, aes(x = year,
                                                 y = value,
                                                 colour = country_name,
                                                 group = country_name)
                            )

interest_exp_line2 <- interest_exp_line +
  geom_line() +
  geom_hline(yintercept = 0)

interest_exp_line3 <- interest_exp_line2 +
  bbc_style() +
  scale_x_date(date_labels = "%Y") +
    theme(axis.title.x = element_text(size = 12), 
        axis.title.y = element_text(size = 12)
        ) +
  labs(title = "Is Ghana the next Zambia?",
       subtitle = "Ghana isn't getting any better...", 
       x = "Year",
       y = "Interest payments\n(% of expenses)")


finalise_plot(plot_name = interest_exp_line3,
              source = "Source: World Bank",
              save_filepath = "c:/workspace/repos/world_bank_data/outputs/figures/ghana_zambia_interest_line.png",
              width_pixels = 640,
              height_pixels = 450
              )

我的情节是这样的:

【问题讨论】:

  • 为了帮助我们帮助您,您能否通过分享您的数据样本来重现您的问题?见how to make a minimal reproducible example。只需在控制台中输入dput(NAME_OF_DATASET) 并将以structure(.... 开头的输出复制并粘贴到您的帖子中。

标签: r date ggplot2 axis-labels


【解决方案1】:

我现在才知道...

它与音阶无关,需要调整主题。我通过使用 plot.margin = margin(10, 15, 10, 10) 更改主题来纠正它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 2021-11-28
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多