我正在嘗試將substitute一些值替換為geom_textabline. 但是,它不斷給我以下錯誤:
錯誤
check_aesthetics():!美學必須是長度 1 或與資料 (1) 相同:標簽
我嘗試將標簽中的運算式轉換為字符,或使用粘貼來加入等,但沒有奏效。
如何在geom_textabline's 標簽中使用 substitude?
dSlope <- 2
gg <- ggplot(mtcars, aes(x=mpg, y=cyl))
#facet_wrap(Y~., scales = "free")
geom_textabline(label = substitute("r = -("*x~ frac(mu*m,s)*") t", list(x = sprintf("%.3f", abs(dSlope))))
, slope = dSlope, intercept = 0
, size = 0.36*fontSize, color = "black", hjust = 0.8, vjust = -0.2, show.legend = FALSE, parse = TRUE)
gg
注意:上面的代碼是一個更大更復雜的代碼的簡化版本。
uj5u.com熱心網友回復:
生成的標簽substitute被解釋為長度為 3。解決方法是deparse替換并使用parse = TRUE:
library(geomtextpath)
#> Loading required package: ggplot2
dSlope <- 2
fontSize <- 16
ggplot(mtcars, aes(mpg, cyl))
geom_textabline(label = deparse(substitute("r = -("*x~ frac(mu*m,s)*") t",
list(x = sprintf("%.3f", abs(dSlope))))),
slope = dSlope, intercept = 0,
size = 0.36*fontSize, color = "black", parse = TRUE,
hjust = 0.4, vjust = -0.2, show.legend = FALSE)

由reprex 包于 2022-05-04 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471599.html
