How can I reverse the axis in a biplot
When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:
These are the functions, I used:
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
plot(pc$x[,1:2], pch=""); text(pc$x[,1:2], cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
biplot(princomp(dat5, cor=T), cex=.5)
How can I change the axis direction of one of those, to make them the same?
r plot axis pca biplot
add a comment |
When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:
These are the functions, I used:
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
plot(pc$x[,1:2], pch=""); text(pc$x[,1:2], cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
biplot(princomp(dat5, cor=T), cex=.5)
How can I change the axis direction of one of those, to make them the same?
r plot axis pca biplot
You second plot is pretty clear, but how did you generate the first one. What ispc
?
– G5W
Nov 21 '18 at 14:12
likely the result ofprcomp
. A reproducible example always helps by the way
– Vincent Bonhomme
Nov 21 '18 at 14:36
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19
add a comment |
When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:
These are the functions, I used:
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
plot(pc$x[,1:2], pch=""); text(pc$x[,1:2], cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
biplot(princomp(dat5, cor=T), cex=.5)
How can I change the axis direction of one of those, to make them the same?
r plot axis pca biplot
When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:
These are the functions, I used:
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
plot(pc$x[,1:2], pch=""); text(pc$x[,1:2], cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
biplot(princomp(dat5, cor=T), cex=.5)
How can I change the axis direction of one of those, to make them the same?
r plot axis pca biplot
r plot axis pca biplot
edited Nov 22 '18 at 18:22
asked Nov 21 '18 at 13:54
Nicole Origami Fox
55
55
You second plot is pretty clear, but how did you generate the first one. What ispc
?
– G5W
Nov 21 '18 at 14:12
likely the result ofprcomp
. A reproducible example always helps by the way
– Vincent Bonhomme
Nov 21 '18 at 14:36
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19
add a comment |
You second plot is pretty clear, but how did you generate the first one. What ispc
?
– G5W
Nov 21 '18 at 14:12
likely the result ofprcomp
. A reproducible example always helps by the way
– Vincent Bonhomme
Nov 21 '18 at 14:36
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19
You second plot is pretty clear, but how did you generate the first one. What is
pc
?– G5W
Nov 21 '18 at 14:12
You second plot is pretty clear, but how did you generate the first one. What is
pc
?– G5W
Nov 21 '18 at 14:12
likely the result of
prcomp
. A reproducible example always helps by the way– Vincent Bonhomme
Nov 21 '18 at 14:36
likely the result of
prcomp
. A reproducible example always helps by the way– Vincent Bonhomme
Nov 21 '18 at 14:36
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19
add a comment |
1 Answer
1
active
oldest
votes
The sign of PCs being arbitrary, you can change it/them by multiplying one or more PCs by -1. Note that this stands only for representation only, depending on what you do, eg if you use $rotation
you may also need to change the corresponding columns as well. An example with iris
follows. Hope this helps.
p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")
plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53413630%2fhow-can-i-reverse-the-axis-in-a-biplot%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
The sign of PCs being arbitrary, you can change it/them by multiplying one or more PCs by -1. Note that this stands only for representation only, depending on what you do, eg if you use $rotation
you may also need to change the corresponding columns as well. An example with iris
follows. Hope this helps.
p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")
plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
|
show 2 more comments
The sign of PCs being arbitrary, you can change it/them by multiplying one or more PCs by -1. Note that this stands only for representation only, depending on what you do, eg if you use $rotation
you may also need to change the corresponding columns as well. An example with iris
follows. Hope this helps.
p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")
plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
|
show 2 more comments
The sign of PCs being arbitrary, you can change it/them by multiplying one or more PCs by -1. Note that this stands only for representation only, depending on what you do, eg if you use $rotation
you may also need to change the corresponding columns as well. An example with iris
follows. Hope this helps.
p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")
plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")
The sign of PCs being arbitrary, you can change it/them by multiplying one or more PCs by -1. Note that this stands only for representation only, depending on what you do, eg if you use $rotation
you may also need to change the corresponding columns as well. An example with iris
follows. Hope this helps.
p <- prcomp(iris[, -5])
plot(p$x[, 1:2], asp=1, xlab="PC1", ylab="PC2")
plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")
edited Nov 21 '18 at 17:11
answered Nov 21 '18 at 14:33
Vincent Bonhomme
4,41711431
4,41711431
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
|
show 2 more comments
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
Thank you Vincent! :)
– Nicole Origami Fox
Nov 22 '18 at 18:20
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
This is how it works for me now:
– Nicole Origami Fox
Nov 22 '18 at 18:35
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
plot(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2");
– Nicole Origami Fox
Nov 22 '18 at 18:36
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
text(cbind(pc$x[,1], pc$x[,2]*-1), asp=1, xlab="PC1", ylab="PC2", cex=.5, labels=(row.names(dat5)), col=as.numeric(dat$ObCl))
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
# I just don't get rid of the symbols with pch="", since I want to use text instead...
– Nicole Origami Fox
Nov 22 '18 at 18:37
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- 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.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2fstackoverflow.com%2fquestions%2f53413630%2fhow-can-i-reverse-the-axis-in-a-biplot%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
You second plot is pretty clear, but how did you generate the first one. What is
pc
?– G5W
Nov 21 '18 at 14:12
likely the result of
prcomp
. A reproducible example always helps by the way– Vincent Bonhomme
Nov 21 '18 at 14:36
Exactly :) Sorry for beeing too short. This is the prcomp code:
– Nicole Origami Fox
Nov 22 '18 at 18:17
(pc <- prcomp(dat5, center=T, retx=T, scale=T)); summary(pc)
– Nicole Origami Fox
Nov 22 '18 at 18:17
Thank you for editing, MrFlick!
– Nicole Origami Fox
Nov 22 '18 at 18:19