Plotting multiple datasets on a 3D plot
$begingroup$
I want to make a 3D scatter plot of multiple data selections on a single plot (i.e same axes).
I know that in 2D this is possible by using par() function like so:
plot(6:25,rnorm(20),type="b",xlim=c(1,30),ylim=c(-2.5,2.5),col=2)
par(new=T)
plot(rnorm(30),type="b",axes=F,col=3)
par(new=F)
(source: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_addat.html)
Can I do something like that on a 3D plot, preferably an interactive 3D plot, like the ones created using plot3D from 'rgl' package?
r visualization
$endgroup$
add a comment |
$begingroup$
I want to make a 3D scatter plot of multiple data selections on a single plot (i.e same axes).
I know that in 2D this is possible by using par() function like so:
plot(6:25,rnorm(20),type="b",xlim=c(1,30),ylim=c(-2.5,2.5),col=2)
par(new=T)
plot(rnorm(30),type="b",axes=F,col=3)
par(new=F)
(source: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_addat.html)
Can I do something like that on a 3D plot, preferably an interactive 3D plot, like the ones created using plot3D from 'rgl' package?
r visualization
$endgroup$
1
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25
add a comment |
$begingroup$
I want to make a 3D scatter plot of multiple data selections on a single plot (i.e same axes).
I know that in 2D this is possible by using par() function like so:
plot(6:25,rnorm(20),type="b",xlim=c(1,30),ylim=c(-2.5,2.5),col=2)
par(new=T)
plot(rnorm(30),type="b",axes=F,col=3)
par(new=F)
(source: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_addat.html)
Can I do something like that on a 3D plot, preferably an interactive 3D plot, like the ones created using plot3D from 'rgl' package?
r visualization
$endgroup$
I want to make a 3D scatter plot of multiple data selections on a single plot (i.e same axes).
I know that in 2D this is possible by using par() function like so:
plot(6:25,rnorm(20),type="b",xlim=c(1,30),ylim=c(-2.5,2.5),col=2)
par(new=T)
plot(rnorm(30),type="b",axes=F,col=3)
par(new=F)
(source: http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_addat.html)
Can I do something like that on a 3D plot, preferably an interactive 3D plot, like the ones created using plot3D from 'rgl' package?
r visualization
r visualization
asked Jun 4 '15 at 18:37
KMPKMP
161
161
1
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25
add a comment |
1
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25
1
1
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
You can use the plot3Drgl
library. E.g.
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
Or you can use plotly
:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
This saves the output as an html file. In order to get this to work, you'll also need to install pandoc. On CentOS/RedHat do yum install pandoc pandoc-citeproc
. On Mac OSX, using homebrew, do brew install pandoc
.
New contributor
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f6005%2fplotting-multiple-datasets-on-a-3d-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You can use the plot3Drgl
library. E.g.
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
Or you can use plotly
:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
This saves the output as an html file. In order to get this to work, you'll also need to install pandoc. On CentOS/RedHat do yum install pandoc pandoc-citeproc
. On Mac OSX, using homebrew, do brew install pandoc
.
New contributor
$endgroup$
add a comment |
$begingroup$
You can use the plot3Drgl
library. E.g.
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
Or you can use plotly
:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
This saves the output as an html file. In order to get this to work, you'll also need to install pandoc. On CentOS/RedHat do yum install pandoc pandoc-citeproc
. On Mac OSX, using homebrew, do brew install pandoc
.
New contributor
$endgroup$
add a comment |
$begingroup$
You can use the plot3Drgl
library. E.g.
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
Or you can use plotly
:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
This saves the output as an html file. In order to get this to work, you'll also need to install pandoc. On CentOS/RedHat do yum install pandoc pandoc-citeproc
. On Mac OSX, using homebrew, do brew install pandoc
.
New contributor
$endgroup$
You can use the plot3Drgl
library. E.g.
library("plot3Drgl")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
plot3d(x=x,y=y,z=z,col=colors)
Or you can use plotly
:
library("plotly")
x <- c(1,2,3,4,5)
y <- c(6,7,8,9,10)
z <- c(11,12,13,14,15)
colors <- c(rep("red",3), rep("blue",2))
df<-as.data.frame(cbind(x,y,z,colors))
colnames(df)<-c("eat", "pork", "chops", "colors")
p <- plot_ly(data=df, x=~eat, y=~pork, z=~chops, color =~colors, colors=c('#BF382A', '#0C4B8E')) %>% ## Like a pipe?
add_markers() %>%
layout(scene = list(xaxis = list(title = 'eat'),
yaxis = list(title = 'pork'),
zaxis = list(title = 'chops')))
htmlwidgets::saveWidget(as_widget(p), "index.html")
This saves the output as an html file. In order to get this to work, you'll also need to install pandoc. On CentOS/RedHat do yum install pandoc pandoc-citeproc
. On Mac OSX, using homebrew, do brew install pandoc
.
New contributor
New contributor
answered 15 hours ago
irritable_phd_syndromirritable_phd_syndrom
1111
1111
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f6005%2fplotting-multiple-datasets-on-a-3d-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
Welcome to the community :) As there are "r" and "data visualization" tags this question is not irrelevant but maybe stackoverflow is a better place to get a helpful answer
$endgroup$
– Kasra Manshaei
Jun 4 '15 at 19:38
$begingroup$
I found one solution to the problem here: <br/> stackoverflow.com/questions/19731187/… <br/> which requires creating a data frame before doing this. I was wondering if there is a simpler, quicker way of doing it.
$endgroup$
– KMP
Jun 4 '15 at 20:25