3d Vector plotting and visualization in R - r

Anyone know of any packages in R that can plot 3D vectors? I would like to plot some vectors over a 3 dimensional data set. I know scatterplot3d looks like it should be able to do the job, but I didn't see any documentation for vectors specifically (I would like to be able to change the origin of vectors as well).

rgl is a great package for 3d plotting. It is very like 2d plotting except that you use plot3d instead of plot. This answer on SO suggests a way to draw arrows in rgl.

Related

3D Visualization: "3D"-geom_rect function in rgl?

Refering to this question I found a solution for my first problem, but know I have a visualization question regarding rgl.
I did a tedious simulation and got a square which fits into this "space" I created with the mentioned code. In 2D I would use geom_rect to visualize it.
Is there a 3D-geom_rect function in rgl or is there a way to get multiple 3D objects in one plot?

Creating a 3D "ribbon" style plot in R

I want to plot the recorded path of an object such as a plane or drone in 3d space using R. The plotted path should be represented by a flat “ribbon” whose orientation perpendicular to the direction of travel changes to reflect the roll of the object. In other words, I want to be able to visualize the path and orientation of the object in one "ribbon" as it banks in turns.
As far as as I can tell, a traditional ribbon plot in R won't allow you to change the orientation in a third dimension.
Matlab and Python have functionality for creating quiver plots where arrows may be placed to indicate the xyz orientation of the object at a given point in time along the path. I cannot find any R packages with similar functionality.
I have played with Plot3D, Plotrgl, Plot3Drgl and cannot find a package that has this capability.
Q1: Are there any packages in R that would support this type of plot?
Q2: If there isn't, how can I go about creating this type of plot R?
Below are examples in Python and Matlab for the 3D quiver type plots, as well as an image demonstrating the ribbon concept I am imagining.
https://medium.com/analytics-vidhya/exploring-data-acquisition-and-trajectory-tracking-with-android-devices-and-python-9fdef38f25ee
Example of 3D quiver plot in python
https://github.com/xioTechnologies/Gait-Tracking-With-x-IMU
Example of 3D quiver plot in matlab
This is an example of what the "ribbon" would look like
Thanks for any help!

Converting xy coordinates to ternary space for ternary plot in R

I have troubles creating a ternary plot. I tried both the functions in the ggtern and Plotly package. I have a set of (x,y) coordinates, all between 0d and 1. When I just do a regular geom_point() plot, I can nicely see the results in Cartesian space.
Then I have tried the ggtern() function after converting my (x,y) coordinates to ternary space but I get a very different result and the points don't show up with a similar distribution as in Cartesian space.
Since I want to make a ternary contour plot, it seems quite necessary I get a similar distribution of points as in Cartesian space.
I tried the following conversion, with different values for 'direction' option:
Ternary_Coords<-as.data.frame(t(XYToTernary(VarX,VarY),direction=2)))
But my points never look the same as on the cartesian plot.
What could the problem be?
Many thanks in advance!

How do you plot a 3d scatterplot with multiple facets?

I'm trying to plot a 3d scatterplot (let's use this previous question as an example), but as a grid with multiple 3D scatterplots on the same page based on a categorical factor. I see how many people can do this with, for example, boxplots, but have no idea how to do so with a 3-d scatterplot. Any thoughts would be very helpful.
You can do this with the cloud function in the lattice package, although it probably doesn't offer as much easy fine-scale control as scatterplot3d- or rgl-based plots:
set.seed(101)
d <- data.frame(x=runif(1000),y=runif(1000),z=runif(1000),
f=factor(sample(1:10,replace=TRUE,size=1000)))
library("lattice")
cloud(z~x*y|f,data=d)

R: levelplot vs. contourplot

I want to plot a contour of my data in R.
What is the difference between levelplot vs. contoutplot in package lattice and latticeExtra in R?
The 'latticeExtra' package contains none of the functions you mention.
Briefly, 'levelplot' fills in colored squares, while 'contourplot' makes curved lines like a topographic map.
But the best way for you to see is to simply look at and run the code for the examples for the two functions in the lattice package.

Resources