R语言ggplot2可视化自动换行适配长文本图例(legend)实战:Multiple Lines for Text per Legend Label

R语言ggplot2可视化自动换行适配长文本图例(legend)实战:Multiple Lines for Text per Legend Label

#导入包及数据处理

library(stringr)
library(tidyverse)

# Create long labels to be wrapped
iris$Species = paste(iris$Species, 
                     "random text to make the labels much much longer than the original labels")

#自动换行适配长文本图例(legend)

library(stringr)
library(tidyverse)

# Create long labels to be wrapped
iris$Species = paste(iris$Species, 
                     "random text to make the labels much much longer than the original labels")

ggplot(iris, aes(Sepal.Length, Sepal.Width, colour=str_wrap(Species,20))) +
  geom_point() +
  labs(colour="Long title shortenednwith wrapping") +
  theme(legend.key.height=unit(2, "cm"))

参考:R

参考:Multiple Lines for Text per Legend Label in ggplot2

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>