R 在图例中包括统计汇总结果

R 在图例中包括统计汇总结果,r,ggplot2,statistics,finance,legend-properties,R,Ggplot2,Statistics,Finance,Legend Properties,我有下面的图,但我想在图中的某个地方-最好在图例中包括描述性统计,如平均值、标准偏差、峰度等。?您可以使用注释和捕获.输出来实现这一点: library(ggplot2) data("iris") m <- loess(Petal.Length ~ Sepal.Length, data = iris) out <- capture.output(print(summary(m))) out2 <- paste0(out[-1], "", collapse = "\n") gg


我有下面的图,但我想在图中的某个地方-最好在图例中包括描述性统计,如平均值、标准偏差、峰度等。?

您可以使用
注释
捕获.输出
来实现这一点:

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)
库(ggplot2)
数据(“iris”)

m您可以使用
注释
捕获。输出

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)
库(ggplot2)
数据(“iris”)

或者这可能吗?使用geom_text()添加您想要的内容!或者这是可能的?使用geom_text()添加您想要的内容!