custom color in PCA analysis

Issue #766 new
Former user created an issue

I have run a PCA analysis per the tutorial on a trajectory and, separately, have scored each step using Rosetta. I would like to color each data point within the PCA plot using a color gradient that corresponds to the Rosetta score (eg blue to red). The rosetta score is loaded as a data frame. Is this feasible to do and can you please provide some guidance on how to do this?

Comments (1)

  1. Xinqiu Yao

    The PCA plot is basically a scatter plot and in R you can color each point differently in a scatter plot. You can use the colorRamp() function from the grDevices package to create a color gradient and then map your (normalized) data to the color. For example,

    ramp <- colorRamp(c("white", "blue"))
    
    # Normalize data; assume the original dataset is called 'dat'
    ndat <- (dat - min(dat)) / (max(dat) - min(dat))
    
    # Define colors
    cols <- rgb(ramp(ndat), max=255)
    
    # Plot
    plot.pca(pc, pc.axes=c(1,2), col=cols) 
    

    Another option is to use the ggplot2 package, which allows a direct map of continuous values to a color bar. You can easily find many documents online for how to use it.

    Hope it may help.

  2. Log in to comment