我试着用geom_text
标记ggplot2中qq图上的点.aesthetic evaluation使用after_stat
函数.计算出的统计数据标记为理论数据,如geom_qq
computed variables的文档中所示,并应可用于geom_text
?这是我第一次使用after_stat
,所以不知道我做错了什么.
以下是我try 的一个例子:
library(ggplot2)
dat <- iris
dat$row <- 1:nrow(dat)
dat |>
ggplot(aes(sample = Petal.Length)) +
geom_qq() +
geom_qq_line() +
geom_text(aes(label = row,
x = after_stat(theoretical),
y = after_stat(sample))) #Trying to label points on qq plot
#> Error in `geom_text()`:
#> ! Problem while mapping stat to aesthetics.
#> ℹ Error occurred in the 3rd layer.
也试过这种方式修改而不是geom_qq
做geom_text
dat |>
ggplot(aes(sample = Petal.Length, label = row)) +
geom_qq(geom = "text") +
geom_qq_line()
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Error in `geom_qq()`:
#> ! Problem while setting up geom.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `compute_geom_1()`:
#> ! `geom_text()` requires the following missing aesthetics: label.