[英]car::scatter3d in R - labeling axis better
I'm using scatter3d and the 3 axes just have two endpoint values. 我正在使用scatter3d,3轴只有两个端点值。 how can I get labels throughout the entire axis, just like the normal plot() function does?
如何在整个轴上获得标签,就像普通的plot()函数一样?
Oh well. 那好吧。 I took it as a challenge.
我认为这是一个挑战。
Obviously you need to: 显然你需要:
require(rgl)
require(car)
require(mgcv) # for the example
Copy the car:::scatter3d.default
code and paste it back, assigning it to scatter3d.default
. 复制
car:::scatter3d.default
代码并将其粘贴回来,并将其分配给scatter3d.default
。
Add these lines early in the code for scatter3d.default
: 在
scatter3d.default
的代码中尽早添加这些行:
showLabels3d <- car:::showLabels3d
nice <- car:::nice
# since you will be losing their connection to the unexposed fns in car
Then in the code block following the second if(axis.scales){ ...}
, substitute this code: 然后在第二个
if(axis.scales){ ...}
之后的代码块中,替换此代码:
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])
}
(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
命名空间,经常派出scatter
法。我只是更换了scatter3d
内通话car:::scatter3d.formula
与“scatter3d.default”等等解释器首先会查看新定义的函数。)
Edit: a better method than mucking with scatter3d.formula
is to assign the car
namespace/environment to the new function with this code: 编辑:比使用
scatter3d.formula
更好的方法是使用以下代码将car
命名空间/环境分配给新函数:
environment(scatter3d.default) <- environment(car:::scatter3d.formula)
Then if you do this: 然后,如果你这样做:
scatter3d(prestige ~ income + education, data=Duncan)
You get this (taken with a screenshot program) 你得到这个(用截图程序拍摄)
There is a new option that adds interior axis labels, from the help of scatter3d
: 在
scatter3d
的帮助下,有一个新选项可以添加内部轴标签:
axis.ticks
axis.ticks
if TRUE, print interior axis-“tick” labels;
如果为TRUE,则打印内部轴 - “勾”标签; the default is FALSE.
默认值为FALSE。 (The code for this option was provided by David Winsemius.)
(此选项的代码由David Winsemius提供。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.