[R] PCA biplot customising point shape and legend
PIKAL Petr
petr@p|k@| @end|ng |rom prechez@@cz
Tue Dec 1 17:16:39 CET 2020
Dear all
I am struggling to customise biplot from FactoMineR pacakge
My code is almost correct but piece of information is missing
Here is data
temp <- structure(list(leukocyte28 = c(96875L, 73438L, 68229L, 94479L,
76563L, 141667L, 111042L, 93333L, 132083L, 103542L, 61667L, 77708L
), macrophage28 = c(60.29, 99.13, 97.04, 98.54, 98.46, 75.2,
89.71, 98, 82, 98.83, 99.08, 98.54), pmn28 = c(38.58, 0.58, 2.71,
0.92, 1, 24.25, 9.29, 1.5, 15.08, 0.92, 0.67, 1), lymphocyte28 = c(1.13,
0.29, 0.25, 0.54, 0.54, 0.55, 1, 0.5, 2.92, 0.25, 0.25, 0.46),
leukocyte3 = c(186042L, 111250L, 114375L, 111146L, 98854L,
156250L, 250625L, 183125L, 202917L, 161875L, 184792L, 128333L
), macrophage3 = c(53.88, 95.96, 98.29, 98.92, 98.92, 78.3,
82.33, 97.83, 84.79, 97.25, 97.75, 98.46), pmn3 = c(44.75,
3.46, 1.29, 0.67, 0.71, 20.4, 16.67, 1.92, 14.04, 1.92, 1.67,
1.21), lymphocyte3 = c(1.38, 0.58, 0.42, 0.42, 0.38, 1.3,
1, 0.25, 1.17, 0.83, 0.58, 0.33), coating = structure(c(3L,
3L, 3L, 1L, 7L, 1L, 2L, 5L, 4L, 6L, 3L, 3L), .Label = c("alumina",
"both", "none", "phosphate", "silica", "tungsten", "zirconia"
), class = "factor"), size = structure(c(1L, 1L, 2L, 2L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L), .Label = c("nano", "pigmentary"
), class = "factor")), class = "data.frame", row.names = c("G1-1",
"G2-5", "G3-1", "G4-19", "G5-4", "G6-3", "G7-5", "G8-2", "G9-5",
"G10-4", "E171-E", "Bayertitan T"))
and the code
library(factoextra)
library(factoMineR)
fit <- PCA(temp[,1:9], quali.sup=9)
fviz_pca_biplot(fit, col.ind = temp$coating, repel=T, col.var = "black",
palette = "lancet", invisible="quali", pointsize=5, pointshape=temp$size,
legend.title = list(col = "Coating"),
xlim=c(-6,6), title="Instillation results")
Which is quite close. Point shapes are triangles and circles in biplot, but
I would like to add them into legend too. If possible I would like to have
also filled shapes instead of open circle and triangle.
I tried many combinations, aded the size variable into PCA, scale_shape and
other options from ggplot but I was not able to get correct second legend
(size).
Any hint is greatly wellcommed.
Best regards.
Petr
More information about the R-help
mailing list