如何使用ggplot绘制3D散点图? [英] How to plot 3D scatter diagram using ggplot?
问题描述
我尝试使用"plotly"功能,但是对于我而言,它根本无法正常工作.在2D情况下,"ggplot"正在工作,但是在增加一个轴时却出现错误.如何解决这个问题?
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()
如何在其中添加一个轴并获得3D图?谢谢你.
How to add one more axis and get the 3D plot in this? Thank You.
推荐答案
由于您用plotly
标记了问题,并说您已尝试将其与plotly一起使用,所以我认为为您提供工作上的帮助会有所帮助plotly
中的代码解决方案:
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 in plotly
:
创建一些要绘制的数据:
Creating some data to plot with:
set.seed(417)
library(plotly)
temp <- rnorm(100, mean=30, sd=5)
pressure <- rnorm(100)
dtime <- 1:100
使用plotly的scatter3d
类型绘制3d散点图:
Graphing your 3d scatterplot using plotly's scatter3d
type:
plot_ly(x=temp, y=pressure, z=dtime, type="scatter3d", mode="markers", color=temp)
呈现以下内容:
ggplot
本身不支持3d图形渲染.
ggplot
as others have note, by itself does not support 3d graphics rendering.
这篇关于如何使用ggplot绘制3D散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!