Plot the PCA Principal Components Analysis in R

Calculating and plot the PCA Principal Components Analysis in R in RStudio example with comments:

# Load data

# Set to data frame
id <-

# set first column as a factor
id$V1 <- factor(id$V1)

# Load first 1200 rows
data <- id[1:1200,]

# Calculate the PCA (Principal Components Analysis)
data.pca <- prcomp(data[, -1], scale = TRUE)

# Calculate the ggplot2 using autoplot
data.plot <- autoplot(data.pca, data = data, colour = 'V1')

# Draw the plot

Now plotting it in RStudio you’ll get your view. So here I have three grouping with legends labels on the right. In this example the column one in the dataset is the group type (0, 1, 2). Autoplot() is just using the ggplot2.

For more information about the prcomp: