I tried to use "plotly" function but It is not working in my case at all. "ggplot" is working is in a case of 2D but it is giving an error when adding one more axis. How to solve this issue?
ggplot(data,aes(x=D1,y=D2,z=D3,color=Sample))+geom_point()
How to add one more axis and get the 3D plot in this? Thank You.
A possible solutions is gg3D.
gg3D is a package created to extend ggplot2 to produce 3D plots. It does exactly what you are asking for: it adds a third axis to a ggplot. I find it quite good and easy to use and that is what I use for my limited needs.
An example taken from the vignette to produce a basic plot
There are other options not involving ggplot. For example the excellent plot3D package with its extension plot3Drgl to plot in openGL.
Since you tagged your question with
plotly
and said that you've tried to use it with plotly, I think it would be helpful to give you a working code solution inplotly
:Creating some data to plot with:
Graphing your 3d scatterplot using plotly's
scatter3d
type:Renders the following:
ggplot
as others have note, by itself does not support 3d graphics rendering.