如何使用 ggplot 绘制 3D 散点图? [英] How to plot 3D scatter diagram using ggplot?

查看:141
本文介绍了如何使用 ggplot 绘制 3D 散点图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I tried to use the plotly package, but it is not working in my case at all. The ggplot package is working for 2D plots 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?

解决方案

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

Graphing your 3d scatterplot using plotly's scatter3d type:

plot_ly(x=temp, y=pressure, z=dtime, type="scatter3d", mode="markers", color=temp)

Renders the following:

ggplot as others have note, by itself does not support 3d graphics rendering.

这篇关于如何使用 ggplot 绘制 3D 散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆