How can I reverse the axis in a biplot












0














When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:



plot(pc...)biplot(princomp...



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?










share|improve this question
























  • 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
















0














When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:



plot(pc...)biplot(princomp...



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?










share|improve this question
























  • 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














0












0








0







When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:



plot(pc...)biplot(princomp...



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?










share|improve this question















When I plot a PCA and then the corresponding biplot, the axis are not always in the same direction, just like in these pictures:



plot(pc...)biplot(princomp...



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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












1 Answer
1






active

oldest

votes


















2














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")


enter image description here



plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")


enter image description here






share|improve this answer























  • 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











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
});


}
});














draft saved

draft discarded


















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









2














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")


enter image description here



plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")


enter image description here






share|improve this answer























  • 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
















2














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")


enter image description here



plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")


enter image description here






share|improve this answer























  • 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














2












2








2






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")


enter image description here



plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")


enter image description here






share|improve this answer














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")


enter image description here



plot(cbind(p$x[, 1], p$x[, 2]*-1), asp=1, xlab="PC1", ylab="PC2")


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python