如何在tag_facets()中创建新行?

发布于 2025-02-12 12:12:21 字数 752 浏览 0 评论 0原文

在图的第一个方面,我在顶角上有一个标题,上面写着“这很有趣”,但我希望它显示为:

this is interesting
what now

每次我放入\ n时我想要一条新行,但是我不确定如何在tag_facets()的上下文中进行操作。

data(iris)
library(ggplot2)
# devtools::install_github("eliocamp/tagger")
library(tagger)


ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  tag_facets(
    tag_pool = c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?"),
    tag_suffix = "",
    position = "tr") +
  theme(tagger.panel.tag.background = element_rect(fill = "white")) + facet_wrap(~Species)

任何指导都将不胜感激!

In the first facet of the graph, I have a caption in the top corner that says, "this is interesting what now" but I would like it to show up as:

this is interesting
what now

Every time I put in \n I would like a new line, but I'm not sure how to do it in the context of tag_facets().

data(iris)
library(ggplot2)
# devtools::install_github("eliocamp/tagger")
library(tagger)


ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  tag_facets(
    tag_pool = c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?"),
    tag_suffix = "",
    position = "tr") +
  theme(tagger.panel.tag.background = element_rect(fill = "white")) + facet_wrap(~Species)

Any guidance would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零崎曲识 2025-02-19 12:12:21

问题是tagger使用gridtext :: richtext_grob在引擎盖下,它允许通过html,css和markdown进行格式化,但需要使用< br> 而不是\ n添加销售折断:

library(ggplot2)
library(tagger)

tag_pool <- c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?")
tag_pool <- gsub("\\n", "<br>", tag_pool)

ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point(aes(color = Species, shape = Species)) +
  xlab("Sepal Length") +
  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  tag_facets(
    tag_pool = tag_pool,
    tag_suffix = "",
    position = "tr"
  ) +
  theme(tagger.panel.tag.background = element_rect(fill = "white")) +
  facet_wrap(~Species)

“”

The issue is that tagger uses gridtext::richtext_grob under the hood which allows for formatting via HTML, CSS and markdown but requires to use <br> instead of \n to add line breaks:

library(ggplot2)
library(tagger)

tag_pool <- c("this is interesting\nwhat now", "for what:\nnow", "hey:\nhow are you?")
tag_pool <- gsub("\\n", "<br>", tag_pool)

ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point(aes(color = Species, shape = Species)) +
  xlab("Sepal Length") +
  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  tag_facets(
    tag_pool = tag_pool,
    tag_suffix = "",
    position = "tr"
  ) +
  theme(tagger.panel.tag.background = element_rect(fill = "white")) +
  facet_wrap(~Species)

梦情居士 2025-02-19 12:12:21

这是你想要的吗?

data(iris)
library(ggplot2)

ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + 
  geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  facet_wrap(~Species)+ 
  geom_label(data = data.frame(x = 6, y = 5, Species = "setosa", 
                              label = "this is interesting\nwhat now"), 
                                  aes(x = x, y = y, label = label), size = 4)

Is this what you want?

data(iris)
library(ggplot2)

ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) + 
  geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width") +
  facet_wrap(~Species)+ 
  geom_label(data = data.frame(x = 6, y = 5, Species = "setosa", 
                              label = "this is interesting\nwhat now"), 
                                  aes(x = x, y = y, label = label), size = 4)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文