我尝试在 ggplot2 库中添加 ggrepel 来绘制图表:
set.seed(42)
ggplot(mtcars) +
geom_point(aes(wt, mpg), size = 5, color = 'grey') +
geom_label_repel(aes(wt, mpg, fill = factor(cyl), label = rownames(mtcars)),
fontface = 'bold', color = 'white',
box.padding = 0.35, point.padding = 0.5,
segment.color = 'grey50') +
theme_classic(base_size = 16)
但我收到以下错误:
Error in convertUnit(x, unitTo, "x", "dimension", "x", "dimension", valueOnly = valueOnly) : 'x' argument must be a unit object
谢谢?
最佳答案
错误的原因是:
box.padding = 0.35, point.padding = 0.5
ggrepel version 0.6.11已更改为接受 0.35
等数字或 unit(0.35, "lines")
返回的值。
如果您使用的是 0.6.11 版本之前的 ggrepel,请尝试使用:
unit(0.35, "lines"), unit(0.5, "lines")
我的猜测是您可能正在使用 CRAN 的 ggrepel 0.6.5。您可以考虑从 CRAN 更新到最新版本,即 0.7.0。
关于r - 错误 - 使用 ggrepel 包在 ggplot2 中可视化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683899/