简体   繁体   中英

Including stat_summary results in legend

***在此处输入图片说明***

I have the following plot, but I would like to within the plot somewhere - preferably in the legend include descriptive statistics, such as mean, std.dev, kurtosis etc. ??

You can do like this using annotate and capture.output :

library(ggplot2)
data("iris")
m <- loess(Petal.Length ~ Sepal.Length, data = iris)
out <- capture.output(print(summary(m)))
out2 <- paste0(out[-1], "", collapse = "\n")

ggplot(iris, aes(Sepal.Length, Petal.Length)) +
  geom_point() +
  geom_smooth() + 
  annotate("text", label = out2, x = 4, y = 5, size = 6, hjust = 0)

Please see the result below.

摘要输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM