问题描述
我使用的是 scatter3d,而 3 个轴只有两个端点值.我怎样才能像普通的 plot() 函数一样在整个轴上获取标签?
I'm using scatter3d and the 3 axes just have two endpoint values. how can I get labels throughout the entire axis, just like the normal plot() function does?
推荐答案
哦.我把它当作一个挑战.
Oh well. I took it as a challenge.
显然你需要:
require(rgl)
require(car)
require(mgcv) # for the example
复制 car:::scatter3d.default
代码并将其粘贴回去,将其分配给 scatter3d.default
.
Copy the car:::scatter3d.default
code and paste it back, assigning it to scatter3d.default
.
在 scatter3d.default
的代码中尽早添加这些行:
Add these lines early in the code for scatter3d.default
:
showLabels3d <- car:::showLabels3d
nice <- car:::nice
# since you will be losing their connection to the unexposed fns in car
然后在第二个 if(axis.scales){ ...}
后面的代码块中,替换此代码:
Then in the code block following the second if(axis.scales){ ...}
, substitute this code:
if (axis.scales) {
x.labels <- seq(lab.min.x, lab.max.x,
by=diff(range(lab.min.x, lab.max.x))/4)
x.at <- seq(min.x, max.x, by=nice(diff(range(min.x, max.x))/4))
rgl.texts(x.at, -0.05, 0, x.labels, col = axis.col[1])
z.labels <- seq(lab.min.z, lab.max.z,
by=diff(range(lab.min.z, lab.max.z))/4)
z.at <- seq(min.z, max.z, by=diff(range(min.z, max.z))/4)
rgl.texts(0, -0.1, z.at, z.labels, col = axis.col[3])
y.labels <- seq(lab.min.y, lab.max.y,
by=diff(range(lab.min.y, lab.max.y))/4)
y.at <- seq(min.y, max.y, by=diff(range(min.y, max.y))/4)
rgl.texts(-0.05, y.at, -0.05, y.labels, col = axis.col[2])
}
(您可能需要替换 scatter3d.formula
的代码,这样就不会在 car
NAMESPACE 中查找常规调度的 scatter
> 方法.我只是将 car::scatter3d.formula
中的 scatter3d
调用替换为scatter3d.default",以便解释器首先查看新定义的函数.)
(You may need to replace the code for scatter3d.formula
so that doesn't look in the car
NAMESPACE for the routinely dispatched scatter
method. I simply replaced the scatter3d
call inside car:::scatter3d.formula
with "scatter3d.default" so the interpreter would first look at the newly defined function.)
比使用 scatter3d.formula
搞砸更好的方法是使用以下代码将 car
命名空间/环境分配给新函数:
a better method than mucking with scatter3d.formula
is to assign the car
namespace/environment to the new function with this code:
environment(scatter3d.default) <- environment(car:::scatter3d.formula)
如果你这样做:
scatter3d(prestige ~ income + education, data=Duncan)
你得到这个(用截图程序拍摄)
You get this (taken with a screenshot program)
这篇关于car::scatter3d in R - 更好地标记轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!