r - 在ggplot2中换行后控制文本大小
问题描述
是否可以在 x 标签文本中在 Stackoverflow 和 Example 上给出不同的大小?
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length)) +
geom_point() + labs(x = 'Stackoverflow\nexample')
解决方案
使用draw_label()
来自cowplot
:
library(ggplot2)
library(cowplot)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length)) +
geom_point() +
xlab("") +
theme(axis.title.x = element_text(size = 10, # you don't need to define size actually
# margin is important to give you some space on the bottom
margin = margin(t = 10, r = 0, b = 0, l = 0,
unit = "mm"))) +
coord_cartesian(clip = "off") +
draw_label("Stackoverflow", x = 3.25, y = 3.5, size = 15) +
# play with x,y to center the text
draw_label("example", x = 3.25, y = 3.25, size = 10)
推荐阅读
- python - 如何使用一些规则将一些纯文本输出转换为 JSON?
- elasticsearch - 弹性转储失败,java script out pf memory
- python - 无法从 Anaconda Navigator 启动 Spyder
- java - 如何在 Java 8 中干净地执行具有异步超时的任务
- c++ - cmake + clang_tidy - 禁用签入目录
- javascript - onclick 内的多个 var:Strings 和 Int
- mysql - SQL 搜索两列并替换第三列
- scala - Bundle 的 Vec 作为 Module 参数
- php - 在mysql中插入来自CSV的10000行数据而不跳过任何行
- javascript - 在渲染方法中访问构造函数变量 - Reactjs