r - R - 在条形图描述中自动设置新行
解决方案
为此,您可以使用stringr::str_wrap()
函数,该函数将字符向量和要放置换行符“\n”的位置作为参数。
这是使用 ggplot2 的可重现示例。
df <- data.frame(label = c(
"This is a very long long long label to wrap in two lines",
"This another very long long long label to wrap in two lines",
"This is third long, very long long label to wrap in two lines"
),
value = c(500, 600, 800)
)
df %>%
ggplot(aes(x = value, y = str_wrap(label, 35))) +
geom_col()
推荐阅读
- c++ - AVX2 列填充计数算法分别在每个位列上
- ios - AVAudioEngine.connect 在硬件而非模拟器上崩溃
- kotlin - Kotlin:不能在外部枚举类中使用来自伴随对象的 const val
- ssh - Is is possible to use the Web Authenitcation API with SSH keys?
- arrays - 用于沿大矩阵的对角线在 3D 数组中插入 nxn 矩阵的代码向量化
- flutter - Flutter - 如何制作一个自定义小部件,为接收到的可滚动小部件添加页脚?
- java - 关系运算中的操作数类型转换
- elasticsearch - ElasticSearch 无痛脚本中的 score_ 始终返回 1
- python - 如何在没有写入所有目录的情况下在 python 中压缩文件
- php - PHP为什么会自动重新声明函数的子函数?