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 at 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
You are missing the point... lattice assembles the entire data set at once so it can adjust and synchronize all of the scales and then it generates an object that can be printed to a device. This approach is entirely incompatible with the base graphics approach of keeping global variables around that help successive functions cooperate to cumulatively build up an image. You need to get all your points into the lattice call initially. which may involve changing how you structure the data before you create the plot. Read the vignette and some tutorials. On February 28, 2019 7:38:52 AM PST, Luigi Marongiu <marongiu.luigi at gmail.com> wrote:>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 at 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) >> > >>-- Sent from my phone. Please excuse my brevity.
Fair enough, thank you. On Thu, Feb 28, 2019 at 4:56 PM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> > You are missing the point... lattice assembles the entire data set at once so it can adjust and synchronize all of the scales and then it generates an object that can be printed to a device. This approach is entirely incompatible with the base graphics approach of keeping global variables around that help successive functions cooperate to cumulatively build up an image. > > You need to get all your points into the lattice call initially. which may involve changing how you structure the data before you create the plot. Read the vignette and some tutorials. > > On February 28, 2019 7:38:52 AM PST, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: > >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 at 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) > >> > > >> > > -- > Sent from my phone. Please excuse my brevity.-- Best regards, Luigi
On 2/28/19 7:56 AM, Jeff Newmiller wrote:> You are missing the point... lattice assembles the entire data set at once so it can adjust and synchronize all of the scales and then it generates an object that can be printed to a device. This approach is entirely incompatible with the base graphics approach of keeping global variables around that help successive functions cooperate to cumulatively build up an image. > > You need to get all your points into the lattice call initially. which may involve changing how you structure the data before you create the plot. Read the vignette and some tutorials.There is an panel.identify.cloud function which will let one interact with a plot as one can do with identify or panel.identify. It calls a function that you can view with: getAnywhere(panel.3didentify) That said, this is only discussing the possibility of adding to an existing 3d plot in theory. I've never done it. I have used some of the other "interaction" plotting functions to add lines and curves to existing plot objects. You can see the options that have been described in: ?panel.identify.cloud ??llines I tried search for prior question on Rhelp but could only find examples where annotation of existing points was attempted, not any examples of adding points. I wondered if one could do it by simply editing the x,y,z? components of an existing lattice object: From object created from the iris dataset: $ panel.args.common:List of 20 ? ..$ x?????????? : num [1:150] 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... ? ..$ y?????????? : num [1:150] 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... ? ..$ z?????????? : num [1:150] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... I tried working with the original example in this thread but originally got an error that on traceback stated that there was a problem with arguments to latticeParseFormula. I didn't see why that would be, but taking out the `ltext` call allowed completion. I then only succeeded in modifying the plot when I prepended new data to the existing vectors, but not when I appended points. Perhaps there is a counter in the lattice object that I have not yet seen. Hope this helps; David.> > On February 28, 2019 7:38:52 AM PST, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: >> 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 at 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) >>>>
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 at 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 at 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 at 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.
Sorry my fingers slipped and hit the send button. One further thing is that I do not know why distribute.type = TRUE for cloud did not work Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2350 -----Original Message----- From: Duncan Mackay [mailto:dulcalma at bigpond.com] Sent: Friday, 5 April 2019 12:48 To: 'Luigi Marongiu' Cc: 'r-help' Subject: RE: [R] add points to lattice cloud plot (3D scatter) 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 at 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 at 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 at 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.