[R] add points to lattice cloud plot (3D scatter)
Duncan Mackay
du|c@|m@ @end|ng |rom b|gpond@com
Fri Apr 5 03:47:48 CEST 2019
Hi all
I know it is a bit late but I have been on other things.
This is a custom solution as it requires manual tweeking for further use in
getting the letter positioning
As cloud is fairly rigid I made a duplicate dataset and reduced the x and y
values by 0.1 as a trial.
Will need tweeking possibly in the z direction if needed.
I then combinded the 2 to form a third to which I assigned a grouping factor
G
df = data.frame(Name = c("A", "B", "C", "D", "E"),
x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
stringsAsFactors = FALSE)
df2 = df
df2[,2] <- df2[,2]-.1
df2[,3] <- df2[,3]-.1
df3 <- rbind(df,df2)
df3$G <- rep(letters[1:2],ea= 5)
After trying to use groups with cloud but this did not work even with
distribute.type = TRUE, I then tried panel.superpose but failed.
Using trellis.print works but ALL the axes must be the same it then it was a
simple matter of superimposing them
x1 =
cloud(z_axis ~ x_axis * y_axis, data = df,
xlab = "X",
ylab = "Y",
zlab = "Z",
xlim = c(-0.691,0.754),
ylim = c(-1.752,1.652),
zlim = c(-0.754,2.213),
scales = list(arrows = FALSE),
pch = c(rep(16,5), 64:69),
type = "b",
col = "red",
cex = 1.5)
x2 =
cloud(z_axis ~ x_axis * y_axis, data = df2,
xlab = "X",
ylab = "Y",
zlab = "Z",
xlim = c(-0.691,0.754),
ylim = c(-1.752,1.652),
zlim = c(-0.754,2.213),
scales = list(arrows = FALSE),
pch = 65:70,
col = "black",
type = "p",
cex = 1.5)
)
print(x1, position = c(0,0,1,1), more = TRUE)
print(x2, position = c(0,0,1,1), more = FALSE)
-----Original Message-----
From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Luigi
Marongiu
Sent: Friday, 1 March 2019 02:39
To: Duncan Murdoch
Cc: r-help
Subject: Re: [R] add points to lattice cloud plot (3D scatter)
I see. I have been thinking of superimposing two plots with
par(new=TRUE), but how could I remove all the graphic parameters
(axes, background etc) keeping only the actual points in lattice? (if
possible).
Tx
On Thu, Feb 28, 2019 at 3:53 PM Duncan Murdoch <murdoch.duncan using gmail.com>
wrote:
>
> On 28/02/2019 5:39 a.m., Luigi Marongiu wrote:
> > Dear all,
> > is it possible to add points to a lattice cloud plot (3D scatter)? I
> > can plot the main data, but what if I wanted to add another point. In
> > R there is the high level plotting function plot(), then the low level
> > points() or lines() etc. What is the equivalent for lattice?
>
> I don't know for sure, but I don't think you can do that in lattice.
> The scatterplot3d::scatterplot3d function returns enough information to
> do this, but I don't think lattice::cloud does. But even
> scatterplot3d::scatterplot3d won't necessarily get it right if points
> hide others that are behind them. It uses the "painter's algorithm",
> and that needs everything to be drawn in just the right order, which you
> probably won't get if you draw things in several calls.
>
> You can draw things in arbitrary order using rgl::plot3d or related
> functions, but you'll need to do more work yourself to get an array of
> plots like lattice gives.
>
> Duncan Murdoch
>
>
> >
> > Thank you
> >
> >
> >>>>
> >
> > df = data.frame(Name = c("A", "B", "C", "D", "E"),
> > x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
> > y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
> > z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
> > stringsAsFactors = FALSE)
> >
> > cloud(z_axis ~ x_axis * y_axis, data = df,
> > xlab = "X", ylab = "Y", zlab = "Z",
> > pch = 16, col = "red", type = "b", cex = 1.5,
> > ltext(x=df$x_axis, y=df$y_axis, z=df$z_axis,
> > labels=df$Names, pos=1, offset=1, cex=0.8)
> > )
> >
> > df2 = data.frame(Name = "F",
> > x_axis = 0.891,
> > y_axis = 2.302
> > z_axis = -1.83,
> > stringsAsFactors = FALSE)
> >
>
--
Best regards,
Luigi
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list