r - 如何在ggplot2中自动获取绘图的中心位置
问题描述
我尝试使用 ggplot2 在我的绘图中添加 R 平方值。
我想把这个值放在这个图的中心位置。
有人能告诉我如何自动获取中心位置(我的代码中的 xposition 和 yposition 值)吗?因为我要制作一堆图,所以我需要自动获取这两个值。
下面是我的代码:
xposition <- 2.5
yposition <- 2.5
plotdata <- data.frame(x=1:10,y=2*(1:10))
relation <- lm(plotdata$y ~ plotdata$x)
lb <- paste("R^2 == ",round(summary(relation)$r.squared,2))
pp <- ggplot(data=plotdata,aes(x=x, y=y)) + geom_point(colour="blue",size=1.5)
pp <- pp + geom_smooth(method = "lm", se = FALSE)
pp <- pp + annotate("text",x=xposition,y=yposition,label=lb, parse=TRUE,size=6)
解决方案
推荐阅读
- nginx - 如何在web服务之前检查入口数据而不慢?
- sonarqube - SonarQube 限制执行的堆大小
- javascript - 如何仅调用最近命中的 api 并在 react-native 中中止先前调用的 api 的会话?
- reactjs - react context vs redux vs hooks,应该考虑哪一个以及每个的不同之处
- laravel - 数据库播种这就是我们使用的原因
- docker - 使用 docker 文件在 Container 中挂载当前目录
- json - 获取在 EXEC() 中执行的动态 PIVOT 结果到 varchar 变量
- android - 当滚动达到高度的 20% 时折叠应用栏布局。我也想 snap 工作
- assembly - bootsect.s:我们如何在将代码本身移开后访问下一行?
- spring-boot - Spring boot 2.1.5、WebFlux、Reactor:如何正确处理MDC