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 shortened\nwith wrapping") +
theme(legend.key.height=unit(2, "cm"))

參考:R
參考:Multiple Lines for Text per Legend Label in ggplot2
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/374553.html
標籤:AI
