示例数据集:
structure(list(Litter = c("Bottle caps & lids", "Bottles < 2 L", "Drink package rings, six-pack rings, ring carriers", "Food containers (fast food, cups, lunch boxes etc.)", "Plastic bags (opaque & clear)", "Cigarettes, butts & filters", "Rope", "Fishing net", "Foam sponge", "Foam (insulation & packaging)", "Clothing, shoes, hats & towels", "Bottles & jars", "Paper (including newspapers & magazines)", "Cups, food trays, food wrappers, cigarette packs etc.", "Footwear (flip-flops)"), Cox.s.Bazar = c(229L, 228L, 73L, 120L, 1311L, 442L, 208L, 125L, 225L, 207L, 29L, 60L, 74L, 96L, 111L), Chittagong = c(13L, 72L, 1L, 7L, 871L, 28L, 59L, 22L, 0L, 382L, 70L, 7L, 249L, 54L, 38L), St..Martin.s.Island = c(29L, 213L, 37L, 45L, 578L, 147L, 30L, 32L, 0L, 48L, 107L, 18L, 48L, 97L, 54L), Kuakata = c(21L, 54L, 0L, 41L, 276L, 87L, 13L, 8L, 0L, 37L, 0L, 7L, 7L, 41L, 12L), Kotka = c(16L, 37L, 3L, 0L, 47L, 19L, 0L, 0L, 0L, 0L, 3L, 0L, 5L, 0L, 0L)), class = "data.frame", row.names = c(NA, -15L))
我尝试解决问题:
install_github("vqv/ggbiplot")
library(devtools)
library(ggbiplot)
data.class <- Mydata[,1]
data.pca <- prcomp(Mydata[,2:6], scale. = TRUE)
g <- ggbiplot(data.pca, obs.scale = 1, var.scale = 1,
groups = data.class, ellipse = TRUE, circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal',
legend.position = 'top')
print(g)