Reputation: 451
I've relatively new to R and I'm not quite sure how to achieve this. Right now I performed PCA on two different data sets using prcomp.
data1.pr <- prcomp(data1, center=TRUE, scale=TRUE)
data2.pr <- prcomp(data2, center=TRUE, scale=TRUE)
I used autoplot(data1.pr, frame = TRUE)
and autoplot(data2.pr, frame = TRUE)
to draw the graph and it shows the results for both data1 and data2:
Now, how do I combine these two pictures together into one plot with different groups? I searched from some answers and it seem geom
is one such solution. However, I'm not quite sure how to achieve that with grouping. Any help would be appreciated!
Upvotes: 0
Views: 1581
Reputation: 1388
Use the following library to control the size(s) of your plots.
library(repr)
options(repr.plot.width = 5, repr.plot.height = 4) # To set plot size
Then use the following code to output your plots side by side - resulting in one plot. . You will need to adjust the height and width (above) to get your desired results.
par(mfrow = c(1, 2) ) # To combine two plots
plot(data1)
plot(data2)
Upvotes: 0