0

我正在玩ggforce图书馆,但在显示长文本时遇到了困难。当要显示的文本有点长时,它会从图中消失(参见示例 #2)。有没有办法解决这个问题?

library(tidyverse)
library(ggforce)
ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_mark_circle(aes(color = Species, label = "Small sentence"),
    expand = unit(0.2, "mm")
  ) +
  geom_point() +
  theme(legend.position = "none") +
  theme_minimal()

这不起作用

ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_mark_circle(aes(color = Species, label = "This is a very long text to display"),
                   expand = unit(0.2, "mm")
  ) +
  geom_point() +
  theme(legend.position = "none") +
  theme_minimal()

reprex 包(v0.3.0)于 2019 年 7 月 25 日创建

4

1 回答 1

1

您可以stringr::str_wrap()tidyverse

ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_mark_circle(
    aes(color = Species, label = str_wrap("This is a very long text to display", 20)),
    expand = unit(0.2, "mm")
  ) +
  geom_point() +
  theme(legend.position = "none") +
  theme_minimal()

在此处输入图像描述

于 2019-07-25T15:10:33.423 回答