【发布时间】:2021-07-30 23:56:21
【问题描述】:
我有一个图表(下面的简化示例),我想将 x 轴放在顶部。标签使用 element_markdown 来包含换行符。
在我添加似乎停止应用换行符的 position = "top" 之前,一切正常。你知道为什么吗?
这就是它应该的样子
并且将 position = "top" 的代码注释掉了。
library(tidyverse, ggtext)
periods <-c(1,2,3)
periodLabels <- c("Jan", "Feb<br>21", "Mar")
data <- data.frame(period = periods,
y = c(10, 20, 30))
ggplot(data, aes(period, y)) +
geom_tile() +
coord_cartesian(expand = FALSE) +
# scales
scale_x_continuous(breaks = periods,
labels = periodLabels#,
#position = "top"
) +
theme_minimal(base_size = 5) +
theme(
axis.text.x = element_markdown(size = 8, lineheight = 1.05)
)
【问题讨论】: