R:将文本添加到绘图区域外右下角的绘图

编程入门 行业动态 更新时间:2024-10-27 23:23:48
本文介绍了R:将文本添加到绘图区域外右下角的绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在 baseR 中绘制多个图形,并且我试图在图形的右下角绘制一个文本.我尝试使用 mtext() 但这并没有给我想要的结果.你会怎么做?最终的想法是生成如下图所示的内容.我怎么能这样做?

I am plotting multiple graphs in baseR and I am trying to plot a text in the lower rightern corner of my plots. I tried using mtext() but this doesn't give me the desired result. How would you do this? The idea in the end is to generate something like the graphic below. How could I do this?

这是我用来生成绘图的代码.

Here is my code I use to generate the plots.

xy <- data.frame(NAME=c("NAME1", "NAME1","NAME1","NAME1","NAME2","NAME2","NAME2"),ID=c(47,47,47,47,259,259,259),YEAR=c(1932,1942,1965,1989,2007,2008,2014),VALUE=c(0,NA,-6,-16,0,-9,-28), test=c("text1","text1","text1","text1","text2","text2","text2")) # split data by index ind <- split(x = xy,f = xy[,'ID']) plot1 <- function(x) { fname <- paste0(x[1, 'ID'], '.png') png(fname, width=1679, height=1165, res=150) par(mar=c(6,8,6,5)) plot(x = c(1946, 2014), y = range(x$VALUE, na.rm=TRUE), type='n', main=x[1, 'NAME'], xlab="Time [Years]", ylab="Value [m]") axis(2, at = seq(-100000, 100000, 100), cex.axis=1, labels=FALSE, tcl=-0.3) points(x[,c('YEAR','VALUE')], type="l", lwd=2) points(x[,c('YEAR','VALUE')], type="p", lwd=1, cex=0.5, pch=21, bg='white') abline(h=0) mtext(x$test, side=1, ) dev.off() } plot2 <- function(x) { fname <- paste0(x[1, 'ID'], '.png') png(fname, width=1679, height=1165, res=150) par(mar=c(6,8,6,5)) plot(x[,c('YEAR','VALUE')], type='n', main=x[1, 'NAME'], xlab="Time [Years]", ylab="value [m]") axis(2, at = seq(-100000, 100000, 100), cex.axis=1, labels=FALSE, tcl=-0.3) points(x[,c('YEAR','VALUE')], type="l", lwd=2) points(x[,c('YEAR','VALUE')], type="p", lwd=1, cex=0.5, pch=21, bg='white') abline(h=0) mtext(x$test, side=1) dev.off() } lapply(ind, function(x) ifelse(any(x$YEAR < 1946 & x$YEAR < 2014), plot2(x), plot1(x)))

推荐答案

plot(1) title(sub="hallo", adj=1, line=3, font=2)

更多推荐

R:将文本添加到绘图区域外右下角的绘图

本文发布于:2023-07-18 05:07:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:右下角   文本   区域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!