# library(ggpca)
# # Example using the iris dataset
# iris_data <- tibble::as_tibble(iris)
# head(iris_data)
# # PCA example with custom labels and titles
# p_pca <- ggpca(iris_data, metadata_cols = "Species", mode = "pca", color_var = "Species", ellipse = TRUE,
# title = "PCA Plot of Iris Dataset", subtitle = "Colored by Species",
# caption = "Data source: iris dataset")
# print(p_pca)
# # t-SNE example with custom labels and titles
# p_tsne <- ggpca(iris_data, metadata_cols = "Species", mode = "tsne", color_var = "Species", ellipse = FALSE,
# tsne_perplexity = 30, title = "t-SNE Plot of Iris Dataset",
# subtitle = "Colored by Species", caption = "Data source: iris dataset")
# print(p_tsne)
# # UMAP example with custom labels and titles
# p_umap <- ggpca(iris_data, metadata_cols = "Species", mode = "umap", color_var = "Species", ellipse = FALSE,
# umap_n_neighbors = 15, title = "UMAP Plot of Iris Dataset",
# subtitle = "Colored by Species", caption = "Data source: iris dataset")
# print(p_umap)
# # PCA example with x-axis density plot only
# p_pca_x <- ggpca(iris_data, metadata_cols = "Species", mode = "pca", color_var = "Species", ellipse = TRUE,
# density_plot = "x", title = "PCA with X-axis Density Plot",
# subtitle = "Iris dataset, colored by Species", caption = "Data source: iris dataset")
# print(p_pca_x)
#
# # PCA example with y-axis density plot only
# p_pca_y <- ggpca(iris_data, metadata_cols = "Species", mode = "pca", color_var = "Species", ellipse = TRUE,
# density_plot = "y", title = "PCA with Y-axis Density Plot",
# subtitle = "Iris dataset, colored by Species", caption = "Data source: iris dataset")
# print(p_pca_y)
# # PCA example with both density plots
# p_pca_both <- ggpca(iris_data, metadata_cols = "Species", mode = "pca", color_var = "Species", ellipse = TRUE,
# density_plot = "both", title = "PCA with Both Density Plots",
# subtitle = "Iris dataset, colored by Species", caption = "Data source: iris dataset")
# print(p_pca_both)
# #REF https://cran.r-project.org/web/packages/ggpca/vignettes/ggpca-examples.html
# #METHOD_2
data(iris)
iris.data <- iris[, grep("Sepal|Petal", colnames(iris))]
iris.labels <- iris[, "Species"]
head(iris.data)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1 5.1 3.5 1.4 0.2
## 2 4.9 3.0 1.4 0.2
## 3 4.7 3.2 1.3 0.2
## 4 4.6 3.1 1.5 0.2
## 5 5.0 3.6 1.4 0.2
## 6 5.4 3.9 1.7 0.4
head(iris.labels)
## [1] setosa setosa setosa setosa setosa setosa
## Levels: setosa versicolor virginica
library(umap)
iris.umap <- umap(iris.data)
iris.umap
## umap embedding of 150 items in 2 dimensions
## object components: layout, data, knn, config
head(iris.umap$layout, 3)
## [,1] [,2]
## [1,] 12.70702 2.895555
## [2,] 11.35596 1.391735
## [3,] 11.60412 1.614591
df <- data.frame(iris.umap$layout[,1], iris.umap$layout[,2], iris.labels)
colnames(df) <- c("X","Y", "Label")
head(df)
## X Y Label
## 1 12.70702 2.895555 setosa
## 2 11.35596 1.391735 setosa
## 3 11.60412 1.614591 setosa
## 4 11.34895 1.517699 setosa
## 5 12.88967 2.632119 setosa
## 6 14.05412 3.138375 setosa
library(ggplot2)
ggplot(df, aes(x =X, y= Y, color = Label))+ geom_point()

# ggplot(df, aes(x = UMAP1, y = UMAP2, color = Label, shape = Label)) +
# geom_point(size = 1, alpha = 0.8) +
# scale_shape_manual(values = c(16, 17)) +
# scale_color_manual(values = c("1" = "#FBB4AE" , "0" = "#CCEBC5")) +
# labs(color = "DILI potential", shape = "DILI potential") +
# theme(
# plot.margin = unit(c(1, 1, 1, 1), "cm"),
# legend.position = c(0.5, 1.05),
# legend.direction = "horizontal",
# panel.background = element_blank(),
# panel.border = element_rect(color = "black", fill = NA, size = 1),
# panel.grid.major = element_line(color = "white", size = 0.5),
# panel.grid.minor = element_blank(),
# axis.ticks = element_line(color = "black", size = 0.5),
# axis.ticks.length = unit(0.1, "cm"),
# axis.text = element_text(
# colour = "black", size = 10, face = "plain", family = "sans"),
# legend.background = element_blank(),
# legend.key = element_rect(colour = NA, fill = NA)
# )
# ggsave(filename = paste0(Sys.Date(),"-","DILI potential.tif"),
# plot = last_plot(), device = "tiff", path = dir_path,
# width = 8, height = 8, units = "cm",
# dpi = 300, limitsize = TRUE,compression = "lzw")