将标签绘制为有边缘的矩形,而不是圆角

Her*_*son 1 label r ggplot2

在ggplot2中使用geom_label(),是否可以使矩形完全正方形而不是圆角?

data(iris)

ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() + 
geom_label(x=4, y=7, label = "Test label")
Run Code Online (Sandbox Code Playgroud)

我想将测试标签周围的圆角矩形弄成正方形。

谢谢。

teu*_*and 5

是的,您可以将该label.r参数设置为 0。

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() +
  geom_label(x=4, y=7, label = "Test label",
             label.r = unit(0, "pt"))
Run Code Online (Sandbox Code Playgroud)

由reprex 包于 2021 年 12 月 18 日创建(v2.0.1)