R用par(new = T)绘制多个序列-轴标签相互重叠,使该图不可读 [英] R Plot multiple series with par(new=T) - axis labels are overlaying each other, making the plot unreadable

查看:859
本文介绍了R用par(new = T)绘制多个序列-轴标签相互重叠,使该图不可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制多个数据序列.

I'm plotting multiple data series.

colos=c('red','green','purple','pink','brown')
par(new=F)
for (i in 1:5)
{
  plot(dat[[i+1]],col=colos[i],cex=marksize,xlab='Reading #',ylab = 'Current')
  par(new=T)
}

我的图看起来像这样:

My plot looks like this:

有没有一种方法可以在每次迭代时覆盖绘图轴,但不覆盖绘图点?

Is there a way I can overwrite the plot axis with each iteration, but not overwrite the plotted points?

推荐答案

您可能想改用linespoints函数.这是我通常如何解决此问题的示例.这样,您只需将点覆盖在现有图的顶部,而不是将一个图绘制在另一个图的顶部.

You may want to use the lines or points function(s) instead. Here's an example of how I usually go about this problem. This way you only overlay points on top of the existing plot, instead of plotting one plot on top of another.

使用原始的plot调用绘制第一个,然后使用lapply覆盖其他列的点.

Plot the first one with your original plot call, then use lapply to overlay the other columns' points on top of that.

set.seed(1)
dat <- data.frame(replicate(5, sample(10)))
colos <- c('red','green','purple','pink','brown')
plot(dat[[1]], col = colos[1], xlab = 'Reading #',   
     ylab = 'Current', ylim = range(as.matrix(dat)))
invisible(lapply(2:ncol(dat), function(i) points(dat[[i]], col = colos[i])))

这篇关于R用par(new = T)绘制多个序列-轴标签相互重叠,使该图不可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆