1

我使用 ggbiplot 来生成双图。我想要不同因子水平的不同颜色的点和代表样本大小的点的大小。让我抓狂的问题是尺寸矢量c(1,2,2,1,3,2,2,1,3,3,2,1,1,1,2,3,2,2,3,1的一部分印在图例中:

在此处输入图像描述

我用了:

library(ggbiplot)
pplot <- function(pcaMatrix, cultures, sample.size = NA, FIRST=1, SECOND=2, ELLIPSE.PROB=0.68, SCALE = FALSE, LABELS=NULL){
  PCA <- prcomp(na.omit(pcaMatrix), scale. = SCALE)
  plot <- ggbiplot(PCA, obs.scale = 1, var.scale = 1, labels=LABELS, ellipse = {Ellipse.prob>0}, groups=cultures, circle = FALSE, choices=c(FIRST,SECOND), ellipse.prob=ELLIPSE.PROB)
  plot <- plot + geom_point(aes_string(colour=cultures, size = sample.size)) #+ scale_size_identity() 
  plot <- plot + scale_color_discrete(name = '')
  plot <- plot + scale_size_continuous(labels = c("200+", "500+", "1000+", "2000+", "4000+"))
  plot <- plot + theme(legend.direction = 'horizontal', legend.position = 'top')
  plot <- plot + theme(aspect.ratio=1)
  print(plot)
}

pplot(grav, grav.cultures, grav.sample, 1,2, ELLIPSE.PROB=0)

在哪里

> head(grav)
      Microlithisme Substrat     BpBG Crans  Gm   PD   F
    1          25.0     29.9 61.94226   0.5 0.3 27.0 0.3
    2          44.8     29.3 20.93023   2.1 0.0 47.9 0.0
    3           7.0     66.2 57.58929   0.5 0.2  5.8 0.2
    4          13.2     12.9 55.41126   6.6 0.0 40.0 0.2
    5           2.0      9.0 75.03045   0.1 0.0  6.9 0.0
    6          16.4     17.3 51.36519   0.9 0.2 20.9 0.1

> head(grav.cultures)
[1] GR GR GR GR GR GR
Levels:  AUR AZI EG EGL GR GR.Italy MAG SOL

修改实际样本大小以手动控制点的大小:

> head(grav.sample)
[1]  360  986  599  457 1222  899

grav.sample[grav.sample>=200 & grav.sample < 500] <- 1
grav.sample[grav.sample>=500 & grav.sample<1000] <- 2
grav.sample[grav.sample>=1000 & grav.sample<2000] <- 3
grav.sample[grav.sample>=2000 & grav.sample<4000] <- 4
grav.sample[grav.sample>=4000 & grav.sample<8000] <- 5

> head(grav.sample)
[1] 1 2 2 1 3 2

我实在想不通这个。为什么我的图例中打印了部分尺寸矢量?

4

0 回答 0