如何阻止geom_point大小显示在图例中

问题描述 投票:0回答:1

我正在尝试使用 PCA 绘制一个简单的图

我已经使用 ggplot2 绘制了这些数据。但尺寸显示在图例上。怎么阻止呢。 这是我的代码。

 > dput(colData)
    structure(list(Sample = c("S21_D2", "S21_D10", "S21_D10", "S21_D15", 
    "S131_D2", "S131_D5", "S131_D10", "S131_D15", "S131_D25", "S131_D30", 
    "S136_D1", "S136_D10", "S136_D15", "S136_D25", "S136_D30", "S251_D2", 
    "S251_D5", "S251_D7", "S251_D15", "S251_D25", "S251_D30", "S1101_D1", 
    "S1101_D2", "S1101_D5", "S1101_D7", "S1101_D10", "S1101_D25", 
    "S1101_D30", "S31_D1", "S31_D2", "S31_D5", "S31_D15", "S31_D25", 
    "S31_D30", "S42_D1", "S42_D2", "S42_D5", "S42_D10", "S42_D15", 
    "S102_D5", "S102_D10", "S102_D15", "S252_D1", "S252_D2", "S252_D5", 
    "S252_D7", "S252_D10", "S252_D15", "S252_D25", "S252_D30", "S22_D1", 
    "S22_D5", "S22_D30", "S41_D1", "S41_D1", "S41_D2", "S41_D15", 
    "S51_D1", "S51_D2", "S51_D5", "S51_D5", "S51_D10", "S51_D15", 
    "S51_D30", "S91_D1", "S91_D2", "S132_D5", "S132_D10", "S132_D25", 
    "S132_D30", "S141_D1", "S141_D2", "S141_D5", "S141_D10", "S143_D1", 
    "S143_D5", "S143_D10", "S143_D15", "S143_D30", "S144_D1", "S144_D2", 
    "S144_D5", "S231_D1", "S231_D2", "S231_D5", "S231_D10", "S231_D15", 
    "S32_D1", "S32_D2", "S32_D5", "S32_D10", "S32_D25", "S32_D30", 
    "S133_D2", "S133_D5", "S133_D15", "S135_D1", "S135_D2", "S142_D1", 
    "S142_D2", "S142_D5", "S142_D10", "S142_D15", "S142_D30"), X = c(-0.223651132267436, 
    -3.57720249744647, -0.290185838025935, 0.382052225732902, -3.91100802161457, 
    -1.62617311694135, -2.74006689481061, -0.622649528873042, -3.9743724035101, 
    -1.77718986052425, -3.07414459033738, -0.418759788748071, 1.25372310154224, 
    1.09496019044704, 0.238266819554441, -3.53808988553327, -2.7363997320598, 
    -8.54578780941788, -4.4762969807406, 1.27139855523864, 0.183947758951385, 
    -0.517583910554412, -0.304410190148505, 0.218109441197244, -0.372963654081768, 
    -0.081296926537109, 0.448045528871169, 0.483347388653263, 0.263389743279879, 
    0.157450088938842, -0.170451093462672, -2.10281204607714, -0.885262489177447, 
    0.0800816356183377, 0.263812820320778, -0.133717685439692, -0.90124437935087, 
    -1.97413329303089, -2.43395987641502, -2.95691653148526, -2.37583143620413, 
    -4.76550463023001, 4.6045098611166, 1.27921839607507, 1.58696436338456, 
    2.75925650511809, 1.24899094205102, 1.46628978694761, 2.39929525580681, 
    -0.456228852703781, 1.05469001487084, 0.265317735487105, 0.55193053063666, 
    1.08802397785104, 0.0548494759755792, -0.173808055618209, -0.807685068586555, 
    0.505558599256045, 1.39615230207476, 1.32618120778712, 0.827256508680758, 
    0.986336568944253, 0.991845184017345, 1.4666614191244, -0.121252078902438, 
    -0.40351865259122, 0.6022352297614, 0.439691367125281, 0.700684465441008, 
    0.671423500850393, 0.754191148626221, 0.0349318887352966, -0.290916374438812, 
    0.636628169009934, 2.08228437192422, 0.224339786691489, 0.090149640294263, 
    0.61160260631243, -0.876607799174393, 2.4993692212104, 1.84175154083908, 
    0.598531717562065, 2.3382687873108, 3.7393203669262, 0.566829766432481, 
    -1.09405844081872, 1.37301025894591, -0.672911618324755, 4.07232035002423, 
    0.264862068719949, 0.674347794898317, 0.0636446734452111, 1.20089589604514, 
    -1.1021774838764, -0.910745669805048, -0.194275879595093, 3.21724100667631, 
    0.0472027413888906, 1.68467275055506, 1.97000208834046, 0.808565762606384, 
    0.688421578389897, 0.644207286065043, 1.27271043277551), Y = c(-0.579839937573458, 
    -2.15512323663576, -0.273884152738988, 0.643371035787867, -1.76950626056927, 
    -0.565203517459582, -1.36949188989911, -0.65200897608952, -0.0318705882862642, 
    -0.111091129373697, -1.72315889030126, -0.614475888757652, 0.379718154981066, 
    0.563094720275958, -0.775055809582619, 0.158338048987629, 0.963661140233892, 
    9.33289391067559, 3.3230211813203, 1.15470304374527, -0.328730868081787, 
    -1.73354574905696, -1.27285400110782, 0.228398086556545, 0.0536641879360032, 
    0.0996760980284058, -0.805605947004645, -0.634464067640303, -0.57882552726797, 
    -0.221462780027063, -1.15119260535424, -4.47998849879228, -2.72724745278307, 
    -0.232274442555513, 1.58845062292781, -0.0514613201994664, -0.753853322460675, 
    0.243282792252653, 1.088775140269, -0.553068064304604, -0.606295097738268, 
    1.3883738408613, 1.45516263329313, 0.36599660675178, -0.0474984383291127, 
    -0.799072343629595, -0.702984163393113, -0.398929109013493, 1.43105614619551, 
    0.0764111195739305, 0.161472327278009, -0.0301078981611765, -0.378237123471118, 
    0.0358853373623658, -0.565057226355628, -0.52258441522509, 0.611815282795243, 
    -0.116306209278117, 1.98909149682229, 0.861438341477269, 0.150655146182104, 
    -1.22268327393422, 0.0952940364639085, -0.129098430978509, -0.858459253118616, 
    -1.1007456065898, -1.20413886175035, -0.837188779014039, -0.842990634928036, 
    0.294351603313769, -0.547886182595126, -1.06016691262797, -0.966644285706046, 
    -0.654633854443642, -1.38169407970147, -0.475697861112972, -0.0555881492221886, 
    1.53103281100899, -0.369733181047836, 0.517365121223683, -0.0503671114860659, 
    -0.469454336968186, 0.393645373207904, -0.316898613837062, -0.395030228935386, 
    0.187678412765698, -0.572666895934754, -0.643297209357882, 11.2460472096459, 
    -0.0397617419377608, 0.162431749388997, 0.844922266006946, -0.412534500135866, 
    -1.03901129611704, -0.647111057394775, 0.372737277859115, 3.27053324484176, 
    0.0587158350346983, 0.411045176265961, -0.692390917255549, -0.478150201304166, 
    -0.473190377127571, 0.0428326775338271, 0.472531545929091), Group = c("A", 
    "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", 
    "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", 
    "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", 
    "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "A", "A", "A", 
    "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", 
    "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", 
    "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", 
    "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B"), 
        Timepoint = c("D2", "D10", "D10", "D15", "D2", "D5", "D10", 
        "D15", "D25", "D30", "D1", "D10", "D15", "D25", "D30", "D2", 
        "D5", "D7", "D15", "D25", "D30", "D1", "D2", "D5", "D7", 
        "D10", "D25", "D30", "D1", "D2", "D5", "D15", "D25", "D30", 
        "D1", "D2", "D5", "D10", "D15", "D5", "D10", "D15", "D1", 
        "D2", "D5", "D7", "D10", "D15", "D25", "D30", "D1", "D5", 
        "D30", "D1", "D1", "D2", "D15", "D1", "D2", "D5", "D5", "D10", 
        "D15", "D30", "D1", "D2", "D5", "D10", "D25", "D30", "D1", 
        "D2", "D5", "D10", "D1", "D5", "D10", "D15", "D30", "D1", 
        "D2", "D5", "D1", "D2", "D5", "D10", "D15", "D1", "D2", "D5", 
        "D10", "D25", "D30", "D2", "D5", "D15", "D1", "D2", "D1", 
        "D2", "D5", "D10", "D15", "D30"), Sex = c("M", "M", "M", 
        "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", 
        "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", 
        "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", 
        "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "F", 
        "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", 
        "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", 
        "F", "F", "F", "F", "M", "M", "M", "M", "M", "M", "M", "M", 
        "F", "F", "F", "F", "F", "F", "F", "F", "F", "M", "M", "F", 
        "F", "F", "F", "F", "F")), class = "data.frame", row.names = c(NA, 
    -104L))

ggplot(data=colData, aes(x=X, y=Y))+
 # geom_point(aes(colour = Timepoint,  shape=Group))+
  geom_point(aes(colour = Timepoint,  shape=Sex, size=2))+
  scale_shape_manual(values = c(M = "\u2642", F = "\u2640"))+
  #geom_text(size=1,nudge_y = 0.05,  check_overlap = FALSE) +
  xlab(paste("PC1 - ", pca.var.per[1], "%", sep="")) +
  ylab(paste("PC2 - ", pca.var.per[2], "%", sep="")) +
  theme_bw() +ggtitle("My PCA Graph")+ 
  theme(plot.title = element_text(hjust = 0.5)) 

除了尺寸出现的问题之外,我还有另一个问题,即保存绘图时男性女性尺寸形状不可见。对于尺寸 2,我可以在 R 中看到它。 附上两张图:一张来自 R 内的屏幕截图 当我保存它时另一个 请帮忙。 谢谢, 米特拉

r ggplot2 size geom-point
1个回答
0
投票

将以下行添加到您的 ggplot 代码中: 指南(大小=“无”)+

© www.soinside.com 2019 - 2024. All rights reserved.