Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:56:20+00:00 2026-06-05T08:56:20+00:00

I am trying to find a way make 3D PCA visualization from R more

  • 0

I am trying to find a way make 3D PCA visualization from R more portable;
I have run a PCA on 2D matrix using prcomp().

  1. How do I export the 3D coordinates of data points, along with labels and colors (RGB) associated with each?
  2. Whats the practical difference with princomp() and prcomp()?
  3. Any ideas on how to best view the 3D PCA plot using HTML5 and canvas?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:56:21+00:00Added an answer on June 5, 2026 at 8:56 am

    Here is an example to work from:

    pc <- prcomp(~ . - Species, data = iris, scale = TRUE)
    
    1. The axis scores are extracted from component x; as such you can just write out (you don’t say how you want the exported) as CSV using:

      write.csv(pc$x[, 1:3], "my_pc_scores.csv")
      

      If you want to assign information to these scores (the colours and labels, which are not something associated with the PCA but something you assign yourself), then add them to the matrix of scores and then export. In the example above there are three species with 50 observations each. If we want that information exported alongside the scores then something like this will work

      scrs <- data.frame(pc$x[, 1:3], Species = iris$Species,
                         Colour = rep(c("red","green","black"), each = 50))
      write.csv(scrs, "my_pc_scores2.csv")
      

      scrs looks like this:

      > head(scrs)
              PC1        PC2         PC3 Species Colour
      1 -2.257141 -0.4784238  0.12727962  setosa    red
      2 -2.074013  0.6718827  0.23382552  setosa    red
      3 -2.356335  0.3407664 -0.04405390  setosa    red
      4 -2.291707  0.5953999 -0.09098530  setosa    red
      5 -2.381863 -0.6446757 -0.01568565  setosa    red
      6 -2.068701 -1.4842053 -0.02687825  setosa    red
      

      Update missed the point about RGB. See ?rgb for ways of specifying this in R, but if all you want are the RGB strings then change the above to use something like

                         Colour = rep(c("#FF0000","#00FF00","#000000"), each = 50)
      

      instead, where you specify the RGB strings you want.

    2. The essential difference between princomp() and prcomp() is the algorithm used to calculate the PCA. princomp() uses a Eigen decomposition of the covariance or correlation matrix whilst prcomp() uses the singular value decomposition (SVD) of the raw data matrix. princomp() only handles data sets where there are at least as many samples (rows) and variables (columns) in your data. prcomp() can handle that type of data and data sets where there are more columns than rows. In addition, and perhaps of greater importance depending on what uses you had in mind, the SVD is preferred over the eigen decomposition for it’s better numerical accuracy.

    3. I have tagged the Q with html5 and canvas in the hope specialists in those can help. If you don’t get any responses, delete point 3 from your Q and start a new one specifically on the topic of displaying the PCs using canvas, referencing this one for detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find a way to make the include_once(); path start from
I have been trying for the last week to find a way to make
I am trying to find a way to make the following (sample) code more
I am trying to find a way to make an auto-run script that when
I have been trying to find a way to make a mouse click programmatically
I'm trying to find a way to make this smaller by using functions/variables in
Using T-SQL, I'm trying to find the easiest way to make: abc.def.ghi/jkl become abc/def/ghi.jkl?
I'm currently trying to find good way to make calls to WCF services in
I'm trying to make a query, but I can't find a way to do
Trying to find a way to send a POST HTTPS request from Python to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.