Skip to contents

Image saving requires kaleido python package setup via reticulate R package. See ?plotly::save_image for more details and setup instructions. Pass in savename with html file extension to avoid these errors.

Usage

plot_PCA_3D(
  df_pca,
  PCs = c(1:3),
  type = c("Scores", "Loadings"),
  anno = NULL,
  annoname = "Sample",
  annotype = "Type",
  annolabel = annoname,
  label = FALSE,
  colors = NULL,
  title = NULL,
  savename = NULL,
  rotate = FALSE,
  width = 10,
  height = 10
)

Arguments

df_pca

string or prcomp obj; (path to) PCA output

PCs

num vector; list of numeric PCs to plot (ex. c(1:3) for first 3 PCs)

type

c("Score", "Loading")

anno

string/df; Annotation info for df_pca with annoname, annotype, and annolabel columns

annoname

string; Colname in anno matching point name

annotype

string; Colname in anno with info to color by

annolabel

string; Colname in anno to label points by, defaults to annoname

label

logical; T to label points

colors

char vector; For discrete annotype, length should be number of unique annotypes or length 2 for continuous annotypes where colors[1] represents low values and colors[2] represents high values.

title

string; Plot title

savename

string; File path to save plot under, html if not an image format

rotate

logical; T to have the HTML widget automatically rotate when opened. Only applicable if savename is not NULL

width

numeric; Saved plot width

height

numeric; Saved plot height if saving as image format

Value

plotly object

Examples

data(iris)
iris$Sample = rownames(iris)
plot_PCA_3D(
  df_pca = Rubrary::run_PCA(t(iris[,c(1:4)]), screeplot = FALSE),
  PCs = c(1:3),
  type = "Scores",
  anno = iris[,c("Sample", "Species")],
  annoname = "Sample", annotype = "Species",
  title = "Iris PCA Scores 3D"
)