从 R 中的绘图中获取 xlim [英] Get xlim from a plot in R

查看:49
本文介绍了从 R 中的绘图中获取 xlim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在同一个图上的历史和密度,我正在尝试这个:

I want an hist and a density on the same plot, I'm trying this:

myPlot <- plot(density(m[,1])), main="", xlab="", ylab="")
par(new=TRUE)

Oldxlim <- myPlot$xlim
Oldylim <- myPlot$ylim

hist(m[,3],xlim=Oldxlim,ylim=Oldylim,prob=TRUE)

但我无法访问 myPlot 的 xlim 和 ylim.

but I can't access myPlot's xlim and ylim.

有没有办法从 myPlot 中获取它们?我还应该做什么?

Is there a way to get them from myPlot? What else should I do instead?

推荐答案

您是否考虑过在第一个图中指定自己的 xlim 和 ylim(将它们设置为适当的值)然后再次使用这些值来设置直方图的限制在第二个情节?

Have you considered specifying your own xlim and ylim in the first plot (setting them to appropriate values) then just using those values again to set the limits on the histogram in the second plot?

仅通过自己绘制密度图,您应该能够计算出两个轴的最小值和最大值的合理值,然后在下面的代码中将这些值替换为 xmin、xmax、ymin 和 ymax.

Just by plotting density on its own you should be able to work out sensible values for the minimum and maximum values for both axes then replace xmin, xmax, ymin and ymax for those values in the code below.

类似的东西;

myPlot <- plot(density(m[,1])), main="", xlab="", ylab="", xlim =c(xmin, xmax), ylim = c(ymin, ymax)

par(new=TRUE)

hist(m[,3],xlim=c(min, max),ylim=c(min, max),prob=TRUE)

这篇关于从 R 中的绘图中获取 xlim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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