首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ggtext : element_markdown不使用position = "top“

ggtext : element_markdown不使用position = "top“
EN

Stack Overflow用户
提问于 2021-05-09 16:49:53
回答 1查看 76关注 0票数 1

我有一个图表(下面是简化的例子),我想把x轴放在最上面。标签使用element_markdown来包含换行符。

这一切都很好,直到我添加position = "top“,这似乎会停止应用换行符。你知道为什么吗?

这就是它应该看起来的样子

并注释掉position = "top“的代码。

代码语言:javascript
复制
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)
  )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-09 16:57:43

您需要在theme中指定正确的元素(现在为axis.text.x.top

代码语言:javascript
复制
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.top = element_markdown(size = 8, lineheight = 1.05)
    )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67455877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档