有什么有效的方法可以标记R中3D图中沿前3个PCA的数据点?

时间:2019-07-17 12:47:52

标签: r ggplot2 dplyr plotly pca

我对标记跨越3个顶级PCA组件的数据点感兴趣。由于我已经对数据进行了PCA处理,因此我很好奇如何指定属于不同类别的数据点的标签并在3D图形中将其可视化。为了处理数据,我使用了dplyr3dscatterplot来渲染应该显示特定颜色数据点的3D图。我仍然没有达到我的期望。我看着SO,人们的形象确实是3D散点图。谁能指出我如何做到这一点?有什么有效的方法可以在3D散点图中标记数据点以及前3个PCA组件?有什么想法吗?

可复制的数据

这是我的复制数据:

> dput(head(my_df,15))
structure(list(SampleID = structure(c(33L, 42L, 52L, 61L, 70L, 
79L, 71L, 80L, 89L, 98L, 35L, 81L, 90L, 99L, 36L), .Label = c("Sample_10", 
"Sample_11", "Sample_12", "Sample_13", "Sample_14", "Sample_15", 
"Sample_18", "Sample_19", "Sample_20", "Sample_21", "Sample_22", 
"Sample_23", "Sample_24", "Sample_25", "Sample_26", "Sample_27", 
"Sample_28", "Sample_29", "Sample_3", "Sample_30", "Sample_31", 
"Sample_32", "Sample_34", "Sample_36", "Sample_37", "Sample_38", 
"Sample_4", "Sample_5", "Sample_6", "Sample_7", "Sample_8", "Sample_9", 
"Tarca_001_P1A01", "Tarca_003_P1A03", "Tarca_004_P1A04", "Tarca_005_P1A05", 
"Tarca_006_P1A06", "Tarca_007_P1A07", "Tarca_008_P1A08", "Tarca_011_P1A11", 
"Tarca_012_P1A12", "Tarca_013_P1B01", "Tarca_015_P1B03", "Tarca_016_P1B04", 
"Tarca_017_P1B05", "Tarca_018_P1B06", "Tarca_019_P1B07", "Tarca_020_P1B08", 
"Tarca_022_P1B10", "Tarca_023_P1B11", "Tarca_024_P1B12", "Tarca_025_P1C01", 
"Tarca_027_P1C03", "Tarca_028_P1C04", "Tarca_029_P1C05", "Tarca_030_P1C06", 
"Tarca_031_P1C07", "Tarca_034_P1C10", "Tarca_035_P1C11", "Tarca_036_P1C12", 
"Tarca_037_P1D01", "Tarca_039_P1D03", "Tarca_040_P1D04", "Tarca_041_P1D05", 
"Tarca_042_P1D06", "Tarca_043_P1D07", "Tarca_046_P1D10", "Tarca_047_P1D11", 
"Tarca_048_P1D12", "Tarca_049_P1E01", "Tarca_051_P1E03", "Tarca_052_P1E04", 
"Tarca_053_P1E05", "Tarca_054_P1E06", "Tarca_055_P1E07", "Tarca_058_P1E10", 
"Tarca_059_P1E11", "Tarca_060_P1E12", "Tarca_061_P1F01", "Tarca_063_P1F03", 
"Tarca_064_P1F04", "Tarca_065_P1F05", "Tarca_066_P1F06", "Tarca_067_P1F07", 
"Tarca_070_P1F10", "Tarca_071_P1F11", "Tarca_072_P1F12", "Tarca_074_P1G02", 
"Tarca_075_P1G03", "Tarca_076_P1G04", "Tarca_077_P1G05", "Tarca_078_P1G06", 
"Tarca_079_P1G07", "Tarca_082_P1G10", "Tarca_083_P1G11", "Tarca_084_P1G12", 
"Tarca_086_P1H02", "Tarca_087_P1H03", "Tarca_088_P1H04", "Tarca_089_P1H05", 
"Tarca_090_P1H06", "Tarca_091_P1H07", "Tarca_094_P1H10", "Tarca_095_P1H11", 
"Tarca_096_P1H12", "Tarca_100_P2D01", "Tarca_101_P2E01", "Tarca_102_P2F01", 
"Tarca_103_P2G01", "Tarca_106_P2B02", "Tarca_107_P2C02", "Tarca_108_P2D02", 
"Tarca_111_P2G02", "Tarca_114_P2B03", "Tarca_115_P2C03", "Tarca_116_P2D03", 
"Tarca_117_P2E03", "Tarca_120_P2H03_2", "Tarca_125_P2E04", "Tarca_126_P2F04", 
"Tarca_127_P2G04", "Tarca_128_P2H04", "Tarca_132_P2D05", "Tarca_133_P2E05", 
"Tarca_135_P2G05", "Tarca_136_P2H05", "Tarca_137_P2A06", "Tarca_138_P2B06", 
"Tarca_139_P2C06", "Tarca_140_P2D06", "Tarca_141_P2E06", "Tarca_144_P2H06", 
"Tarca_145_P2A07", "Tarca_146_P2B07", "Tarca_147_P2C07", "Tarca_148_P2D07", 
"Tarca_149_P2E07", "Tarca_150_P2F07", "Tarca_151_P2G07", "Tarca_152_P2H07", 
"Tarca_153_P2A08", "Tarca_154_P2B08", "Tarca_155_P2C08", "Tarca_156_P2D08", 
"Tarca_157_P2E08", "Tarca_158_P2F08", "Tarca_159_P2G08", "Tarca_160_P2H08", 
"Tarca_162_P2B09", "Tarca_163_P2C09", "Tarca_165_P2E09", "Tarca_166_P2F09", 
"Tarca_167_P2G09", "Tarca_168_P2H09", "Tarca_169_P2A10", "Tarca_170_P2B10", 
"Tarca_173_P2E10", "Tarca_174_P2F10", "Tarca_175_P2G10", "Tarca_176_P2H10", 
"Tarca_177_P2A11", "Tarca_178_P2B11", "Tarca_179_P2C11", "Tarca_180_P2D11", 
"Tarca_183_P2G11", "Tarca_184_P2H11", "Tarca_185_P2A12", "Tarca_186_P2B12", 
"Tarca_188_P2D12", "Tarca_189_P2E12", "Tarca_190_P2F12", "Tarca_192_P2H12", 
"Tarca_195_P3C01", "Tarca_196_P3D01", "Tarca_197_P3E01", "Tarca_199_P3G01", 
"Tarca_200_P3H01", "Tarca_201_P3A02", "Tarca_202_P3B02", "Tarca_203_P3C02", 
"Tarca_204_P3D02", "Tarca_205_P3E02", "Tarca_206_P3F02", "Tarca_207_P3G02", 
"Tarca_208_P3H02", "Tarca_209_P3A03", "Tarca_210_P3B03", "Tarca_211_P3C03", 
"Tarca_212_P3D03", "Tarca_213_P3E03", "Tarca_214_P3F03", "Tarca_216_P3H03", 
"Tarca_217_P3A04", "Tarca_218_P3B04", "Tarca_219_P3C04", "Tarca_223_P3G04", 
"Tarca_224_P3H04", "Tarca_225_P3A05", "Tarca_226_P3B05", "Tarca_227_P3C05", 
"Tarca_228_P3D05", "Tarca_229_P3E05", "Tarca_230_P3F05", "Tarca_231_P3G05", 
"Tarca_232_P3H05", "Tarca_233_P3A06", "Tarca_234_P3B06", "Tarca_235_P3C06", 
"Tarca_236_P3D06", "Tarca_237_P3E06", "Tarca_238_P3F06", "Tarca_239_P3G06", 
"Tarca_240_P3H06", "Tarca_241_P3A07", "Tarca_242_P3B07", "Tarca_243_P3C07", 
"Tarca_244_P3D07", "Tarca_245_P3E07", "Tarca_246_P3F07", "Tarca_249_P3A08", 
"Tarca_250_P3B08", "Tarca_251_P3C08", "Tarca_252_P3D08", "Tarca_255_P3G08", 
"Tarca_256_P3H08", "Tarca_258_P3B09", "Tarca_259_P3C09", "Tarca_261_P3E09", 
"Tarca_262_P3F09", "Tarca_264_P3H09", "Tarca_266_P3B10", "Tarca_267_P3C10", 
"Tarca_268_P3D10", "Tarca_269_P3E10", "Tarca_270_P3F10", "Tarca_271_P3G10", 
"Tarca_272_P3H10", "Tarca_274_P3B11", "Tarca_275_P3C11", "Tarca_279_P3G11", 
"Tarca_280_P3H11", "Tarca_282_P3B12", "Tarca_283_P3C12", "Tarca_289_P4A01", 
"Tarca_290_P4B01", "Tarca_291_P4C01", "Tarca_292_P4D01", "Tarca_293_P4E01", 
"Tarca_294_P4F01", "Tarca_295_P4G01", "Tarca_296_P4H01", "Tarca_297_P4A02", 
"Tarca_298_P4B02", "Tarca_302_P4F02", "Tarca_305_P4A03", "Tarca_306_P4B03", 
"Tarca_307_P4C03", "Tarca_310_P4F03", "Tarca_311_P4G03", "Tarca_312_P4H03", 
"Tarca_313_P4A04", "Tarca_314_P4B04", "Tarca_315_P4C04", "Tarca_316_P4D04", 
"Tarca_317_P4E04", "Tarca_319_P4G04", "Tarca_320_P4H04", "Tarca_321_P4A05", 
"Tarca_324_P4D05", "Tarca_325_P4E05", "Tarca_326_P4F05", "Tarca_327_P4G05", 
"Tarca_328_P4H05", "Tarca_329_P4A06", "Tarca_330_P4B06", "Tarca_331_P4C06", 
"Tarca_332_P4D06", "Tarca_333_P4E06", "Tarca_334_P4F06", "Tarca_335_P4G06", 
"Tarca_336_P4H06", "Tarca_337_P4A07", "Tarca_338_P4B07", "Tarca_339_P4C07", 
"Tarca_340_P4D07", "Tarca_341_P4E07", "Tarca_342_P4F07", "Tarca_343_P4G07", 
"Tarca_344_P4H07", "Tarca_345_P4A08", "Tarca_346_P4B08", "Tarca_347_P4C08", 
"Tarca_348_P4D08", "Tarca_349_P4E08", "Tarca_350_P4F08", "Tarca_351_P4G08", 
"Tarca_352_P4H08", "Tarca_354_P4B09", "Tarca_356_P4D09", "Tarca_357_P4E09", 
"Tarca_359_P4G09", "Tarca_360_P4H09", "Tarca_361_P4A10", "Tarca_362_P4B10", 
"Tarca_363_P4C10", "Tarca_364_P4D10", "Tarca_366_P4F10", "Tarca_367_P4G10", 
"Tarca_369_P4A11", "Tarca_370_P4B11", "Tarca_371_P4C11", "Tarca_372_P4D11", 
"Tarca_373_P4E11", "Tarca_374_P4F11", "Tarca_375_P4G11", "Tarca_377_P4A12", 
"Tarca_378_P4B12", "Tarca_379_P4C12", "Tarca_380_P4D12", "Tarca_381_P4E12", 
"Tarca_382_P4F12", "Tarca_383_P4G12", "Tarca_384_P4H12", "Tarca_385_P5A01", 
"Tarca_387_P5C01", "Tarca_389_P5E01", "Tarca_390_P5F01", "Tarca_391_P5G01", 
"Tarca_395_P5C02", "Tarca_396_P5D02", "Tarca_397_P5E02", "Tarca_398_P5F02", 
"Tarca_399_P5G02", "Tarca_400_P5H02", "Tarca_401_P5A03", "Tarca_402_P5B03", 
"Tarca_404_P5D03", "Tarca_407_P5G03", "Tarca_408_P5H03", "Tarca_409_P5A04", 
"Tarca_410_P5B04", "Tarca_411_P5C04", "Tarca_412_P5D04", "Tarca_413_P5E04", 
"Tarca_414_P5F04", "Tarca_415_P5G04", "Tarca_416_P5H04", "Tarca_418_P5B05", 
"Tarca_419_P5C05", "Tarca_422_P5F05", "Tarca_423_P5G05", "Tarca_424_P5H05", 
"Tarca_425_P5A06", "Tarca_426_P5B06", "Tarca_428_P5D06", "Tarca_430_P5F06", 
"Tarca_432_P5H06", "Tarca_435_P5C07", "Tarca_436_P5D07", "Tarca_437_P5E07", 
"Tarca_438_P5F07", "Tarca_439_P5G07", "Tarca_440_P5H07", "Tarca_441_P5A08", 
"Tarca_445_P5E08", "Tarca_446_P5F08", "Tarca_447_P5G08", "Tarca_448_P5H08", 
"Tarca_449_P5A09", "Tarca_450_P5B09", "Tarca_451_P5C09", "Tarca_452_P5D09", 
"Tarca_453_P5E09", "Tarca_454_P5F09", "Tarca_456_P5H09", "Tarca_457_P5A10", 
"Tarca_458_P5B10", "Tarca_459_P5C10", "Tarca_460_P5D10", "Tarca_461_P5E10", 
"Tarca_462_P5F10", "Tarca_463_P5G10", "Tarca_464_P5H10", "Tarca_465_P5A11", 
"Tarca_467_P5C11", "Tarca_468_P5D11", "Tarca_469_P5E11", "Tarca_470_P5F11", 
"Tarca_471_P5G11", "Tarca_472_P5H11", "Tarca_474_P5B12", "Tarca_475_P5C12", 
"Tarca_476_P5D12", "Tarca_477_P5E12", "Tarca_478_P5F12", "Tarca_479_P5G12", 
"Tarca_480_P5H12", "Tarca_481_P6A01", "Tarca_482_P6B01", "Tarca_486_P6F01", 
"Tarca_487_P6G01", "Tarca_488_P6H01", "Tarca_489_P6A02", "Tarca_490_P6B02", 
"Tarca_491_P6C02", "Tarca_492_P6D02", "Tarca_493_P6E02", "Tarca_494_P6F02", 
"Tarca_496_P6H02", "Tarca_497_P6A03", "Tarca_498_P6B03", "Tarca_499_P6C03", 
"Tarca_500_P6D03", "Tarca_501_P6E03", "Tarca_502_P6F03", "Tarca_503_P6G03", 
"Tarca_504_P6H03", "Tarca_505_P6A04", "Tarca_506_P6B04", "Tarca_509_P6E04", 
"Tarca_510_P6F04", "Tarca_511_P6G04", "Tarca_514_P6B05", "Tarca_515_P6C05", 
"Tarca_517_P6E05", "Tarca_518_P6F05", "Tarca_519_P6G05", "Tarca_523_P6C06", 
"Tarca_524_P6D06", "Tarca_526_P6F06", "Tarca_527_P6G06", "Tarca_528_P6H06", 
"Tarca_529_P6A07", "Tarca_530_P6B07", "Tarca_532_P6D07_2", "Tarca_535_P6G07", 
"Tarca_536_P6H07", "Tarca_537_P6A08", "Tarca_538_P6B08", "Tarca_539_P6C08", 
"Tarca_540_P6D08", "Tarca_541_P6E08", "Tarca_542_P6F08", "Tarca_543_P6G08", 
"Tarca_544_P6H08", "Tarca_545_P6A09", "Tarca_546_P6B09", "Tarca_547_P6C09", 
"Tarca_548_P6D09", "Tarca_549_P6E09", "Tarca_550_P6F09", "Tarca_551_P6G09", 
"Tarca_552_P6H09", "Tarca_553_P6A10", "Tarca_554_P6B10", "Tarca_556_P6D10", 
"Tarca_557_P6E10", "Tarca_558_P6F10", "Tarca_559_P6G10", "Tarca_560_P6H10", 
"Tarca_561_P6A11", "Tarca_562_P6B11", "Tarca_565_P6E11", "Tarca_566_P6F11", 
"Tarca_567_P6G11", "Tarca_568_P6H11", "Tarca_569_P6A12", "Tarca_570_P6B12", 
"Tarca_576_P6H12", "Tarca_578_P7B01", "Tarca_579_P7C01", "Tarca_580_P7D01", 
"Tarca_581_P7E01", "Tarca_582_P7F01", "Tarca_583_P7G01", "Tarca_584_P7H01_2", 
"Tarca_585_P7A02", "Tarca_586_P7B02", "Tarca_587_P7C02", "Tarca_588_P7D02", 
"Tarca_589_P7E02", "Tarca_590_P7F02", "Tarca_591_P7G02", "Tarca_592_P7H02", 
"Tarca_593_P7A03", "Tarca_594_P7B03", "Tarca_595_P7C03", "Tarca_597_P7E03", 
"Tarca_598_P7F03", "Tarca_599_P7G03", "Tarca_600_P7H03", "Tarca_601_P7A04", 
"Tarca_605_P7E04", "Tarca_606_P7F04", "Tarca_607_P7G04", "Tarca_609_P7A05", 
"Tarca_611_P7C05", "Tarca_612_P7D05", "Tarca_613_P7E05", "Tarca_614_P7F05", 
"Tarca_615_P7G05", "Tarca_616_P7H05", "Tarca_617_P7A06", "Tarca_618_P7B06", 
"Tarca_619_P7C06", "Tarca_620_P7D06", "Tarca_621_P7E06", "Tarca_622_P7F06", 
"Tarca_623_P7G06", "Tarca_624_P7H06", "Tarca_625_P7A07", "Tarca_626_P7B07", 
"Tarca_628_P7D07", "Tarca_629_P7E07", "Tarca_630_P7F07", "Tarca_631_P7G07", 
"Tarca_632_P7H07", "Tarca_633_P7A08", "Tarca_634_P7B08", "Tarca_635_P7C08", 
"Tarca_636_P7D08", "Tarca_637_P7E08", "Tarca_638_P7F08", "Tarca_639_P7G08", 
"Tarca_640_P7H08", "Tarca_641_P7A09", "Tarca_642_P7B09", "Tarca_643_P7C09", 
"Tarca_646_P7F09", "Tarca_647_P7G09", "Tarca_648_P7H09_2", "Tarca_649_P7A10", 
"Tarca_650_P7B10", "Tarca_651_P7C10", "Tarca_652_P7D10", "Tarca_653_P7E10", 
"Tarca_654_P7F10", "Tarca_655_P7G10", "Tarca_656_P7H10", "Tarca_659_P7C11", 
"Tarca_660_P7D11", "Tarca_663_P7G11", "Tarca_664_P7H11", "Tarca_665_P7A12", 
"Tarca_666_P7B12", "Tarca_667_P7C12", "Tarca_668_P7D12", "Tarca_669_P7E12", 
"Tarca_670_P7F12", "Tarca_671_P7G12", "Tarca_672_P7H12", "Tarca_674_P8B01", 
"Tarca_675_P8C01", "Tarca_676_P8D01", "Tarca_677_P8E01", "Tarca_678_P8F01", 
"Tarca_682_P8B02", "Tarca_683_P8C02", "Tarca_684_P8D02", "Tarca_688_P8H02", 
"Tarca_689_P8A03", "Tarca_690_P8B03", "Tarca_692_P8D03", "Tarca_698_P8B04", 
"Tarca_699_P8C04", "Tarca_700_P8D04", "Tarca_701_P8E04", "Tarca_702_P8F04", 
"Tarca_703_P8G04", "Tarca_704_P8H04", "Tarca_707_P8C05", "Tarca_709_P8E05", 
"Tarca_712_P8H05", "Tarca_713_P8A06", "Tarca_714_P8B06", "Tarca_715_P8C06", 
"Tarca_716_P8D06", "Tarca_717_P8E06", "Tarca_718_P8F06", "Tarca_719_P8G06", 
"Tarca_720_P8H06", "Tarca_721_P8A07", "Tarca_722_P8B07", "Tarca_723_P8C07", 
"Tarca_726_P8F07", "Tarca_727_P8G07", "Tarca_728_P8H07", "Tarca_730_P8B08", 
"Tarca_731_P8C08", "Tarca_732_P8D08", "Tarca_733_P8E08", "Tarca_734_P8F08", 
"Tarca_736_P8H08", "Tarca_738_P8B09", "Tarca_739_P8C09", "Tarca_740_P8D09", 
"Tarca_741_P8E09", "Tarca_742_P8F09", "Tarca_743_P8G09", "Tarca_744_P08H09", 
"Tarca_745_P08A10", "Tarca_746_P8B10", "Tarca_749_P8E10", "Tarca_750_P8F10", 
"Tarca_751_P8G10", "Tarca_752_P8H10", "Tarca_754_P8B11", "Tarca_755_P8C11", 
"Tarca_756_P8D11", "Tarca_759_P8G11", "Tarca_760_P8H11", "Tarca_762_P08B12", 
"Tarca_763_P8C12", "Tarca_764_P8D12", "Tarca_765_P8E12", "Tarca_766_P8F12", 
"Tarca_768_P8H12", "Tarca_769_P9A01", "Tarca_770_P9B01", "Tarca_771_P9C01", 
"Tarca_773_P9E01", "Tarca_774_P9F01", "Tarca_775_P9G01", "Tarca_777_P9A02", 
"Tarca_778_P9B02", "Tarca_782_P9F02", "Tarca_784_P9H02", "Tarca_785_P9A03", 
"Tarca_786_P9B03", "Tarca_787_P9C03", "Tarca_789_P9E03", "Tarca_790_P9F03", 
"Tarca_791_P9G03", "Tarca_793_P9A04", "Tarca_794_P9B04", "Tarca_795_P9C04", 
"Tarca_797_P9E04", "Tarca_798_P9F04", "Tarca_799_P9G04", "Tarca_800_P9H04", 
"Tarca_801_P9A05", "Tarca_802_P9B05", "Tarca_803_P9C05", "Tarca_806_P9F05", 
"Tarca_807_P9G05", "Tarca_808_P9H05", "Tarca_809_P9A06", "Tarca_810_P9B06", 
"Tarca_811_P9C06", "Tarca_812_P9D06", "Tarca_813_P9E06", "Tarca_814_P9F06", 
"Tarca_815_P9G06", "Tarca_816_P9H06", "Tarca_817_P9A07", "Tarca_818_P9B07", 
"Tarca_820_P9D07", "Tarca_821_P9E07", "Tarca_822_P9F07", "Tarca_824_P9H07", 
"Tarca_826_P9B08", "Tarca_827_P9C08", "Tarca_828_P9D08", "Tarca_829_P9E08", 
"Tarca_830_P9F08", "Tarca_831_P9G08", "Tarca_832_P9H08", "Tarca_834_P9B09", 
"Tarca_835_P9C09", "Tarca_836_P9D09", "Tarca_837_P9E09", "Tarca_838_P9F09", 
"Tarca_839_P9G09", "Tarca_841_P8A10", "Tarca_842_P8B10", "Tarca_843_P8C10", 
"Tarca_844_P8D10", "Tarca_845_P8E10", "Tarca_847_P8G10", "Tarca_849_P8A11", 
"Tarca_850_P8B11", "Tarca_851_P8C11", "Tarca_852_P8D11", "Tarca_855_P8G11", 
"Tarca_856_P8H11", "Tarca_857_P8A12", "Tarca_858_P8B12", "Tarca_859_P8C12", 
"Tarca_860_P8D12_3", "Tarca_861_P8E12", "Tarca_863_P8G12", "Tarca_864_P8H12", 
"Tarca_866_P10B01", "Tarca_867_P10C01", "Tarca_868_P10D01", "Tarca_869_P10E01", 
"Tarca_870_P10F01", "Tarca_874_P10B02", "Tarca_875_P10C02", "Tarca_876_P10D02", 
"Tarca_878_P10F02", "Tarca_879_P10G02", "Tarca_880_P10H02", "Tarca_881_P10A03", 
"Tarca_884_P10D03", "Tarca_885_P10E03", "Tarca_886_P10F03", "Tarca_888_P10H03", 
"Tarca_890_P10B04", "Tarca_891_P10C04", "Tarca_892_P10D04", "Tarca_893_P10E04", 
"Tarca_895_P10G04", "Tarca_896_P10H04", "Tarca_897_P10A05", "Tarca_899_P10C05", 
"Tarca_900_P10D05", "Tarca_903_P10G05", "Tarca_904_P10H05", "Tarca_905_P10A06", 
"Tarca_906_P10B06", "Tarca_907_P10C06", "Tarca_908_P10D06", "Tarca_909_P10E06", 
"Tarca_910_P10F06", "Tarca_911_P10G06", "Tarca_912_P10H06", "Tarca_913_P10A07", 
"Tarca_914_P10B07", "Tarca_915_P10C07", "Tarca_916_P10D07", "Tarca_917_P10E07", 
"Tarca_918_P10F07", "Tarca_919_P10G07", "Tarca_920_P10H07"), class = "factor"), 
    GA = c(11, 15.3, 21.7, 26.7, 31.3, 32.1, 19.7, 23.6, 27.6, 
    30.6, 32.6, 12.6, 18.6, 25.6, 30.6), Batch = c(1L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L), Set = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("GSE113966", 
    "PRB_HTA"), class = "factor"), Train = c(1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Platform = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "HTA20", class = "factor"), 
    `1_at` = c(6.06221469449721, 6.12502298793819, 5.8755020052495, 
    6.12613148162098, 6.146466258537, 6.1345548976595, 6.28953417729806, 
    6.32099748158838, 6.1855043077415, 6.08561779473768, 6.15856026391669, 
    6.01545219066942, 6.25857984382111, 6.36882457350296, 6.22016811759586
    ), `10_at` = c(3.79648446367096, 3.8053045883833, 3.45024474095539, 
    3.62841140410044, 3.44681241591488, 3.51232455992681, 3.56819306931016, 
    3.58462249988614, 3.6962578620003, 3.54911765491621, 3.72853662804593, 
    3.45867791579279, 3.59024881523945, 3.82181133052338, 3.69553021972333
    ), `100_at` = c(5.84933778267459, 6.19156161924549, 6.55052475296263, 
    6.42187743053935, 6.26096240773642, 6.15489279092855, 6.34807354206396, 
    6.17574188244964, 6.1797131132904, 6.11780116002087, 6.20323373624061, 
    6.1848681809123, 6.24635169763079, 6.28175898350025, 6.25479583503303
    ), `1000_at` = c(3.5677794435745, 3.45252405345375, 3.31613364795286, 
    3.43245075704917, 3.47716215037972, 3.63813996294905, 3.39904385276621, 
    3.78739437083121, 3.45201439858256, 3.54214650423219, 3.53369876966333, 
    3.44895159550441, 3.51532853598111, 3.54203947069514, 3.50451431462302
    ), `10000_at` = c(6.16681461038468, 5.67837335902992, 6.18505928400759, 
    5.6337568741831, 5.31319800115, 5.14814946571171, 5.64064316609978, 
    5.27090621047048, 5.69462506828168, 6.25755205471611, 5.7482549816934, 
    5.72613754557569, 5.68110995701518, 5.25478756786505, 5.14171528059565
    ), `100009613_at` = c(4.44302662142323, 4.77319948223297, 
    4.3934877055859, 4.6237834519809, 4.42265091096155, 4.66743523288194, 
    4.97483476597509, 4.73415116097344, 4.62910041308852, 4.78673497541689, 
    4.59759663067063, 4.62453903712286, 4.77791032146269, 4.79471989245065, 
    4.64089637146557), `100009676_at` = c(5.83652223195279, 6.14339793828768, 
    5.89836406552412, 6.01979203584278, 6.40769927365462, 5.98400432133011, 
    6.1149144301085, 6.05331581275033, 6.06510349557878, 5.74573650612351, 
    5.98719369609302, 6.0074614887814, 6.04564052289621, 6.12939953093625, 
    6.10594091413241), `10001_at` = c(6.33001755606083, 5.60174509461169, 
    6.13798360106589, 5.78750241567476, 5.83043737364811, 5.5920698678248, 
    5.84077907831575, 5.67929642825133, 5.96981067663553, 6.19490161026853, 
    5.75603515793641, 5.87493644012563, 5.80941714030283, 5.55586165971229, 
    5.80320733931781), `10002_at` = c(4.92233877299356, 4.71176546418277, 
    4.62812370798939, 4.79628294150335, 4.72648756689738, 4.79729686531453, 
    4.91913790102029, 4.88163201331439, 4.78507064150637, 4.79997095951811, 
    4.73932005879352, 4.85697540024369, 4.90838062744781, 4.86898558320241, 
    4.73415922096939), `10003_at` = c(2.68934375273141, 2.77100972258672, 
    2.55675627493564, 2.61341541015611, 2.63187842412618, 2.69430042092269, 
    2.73207812554522, 2.69169494424212, 2.63508499699814, 2.65268941561582, 
    2.78546450421772, 2.78129834839264, 2.66697993437978, 2.6990956336608, 
    2.59784138580729), `100033411_at` = c(2.74561888109989, 3.26357660188778, 
    2.70765553292035, 2.80774129091983, 2.76338705394557, 2.8653583834812, 
    3.00137677271996, 3.03783869301541, 3.084972389632, 2.83262780533507, 
    2.86173816184281, 2.99607734866458, 2.85563184073152, 3.13196264891025, 
    2.9364732038239), `100033413_at` = c(2.76060893169324, 2.40289892571191, 
    3.03645581534102, 2.64583376265592, 3.10581884436122, 3.24800269901788, 
    2.62090678070501, 2.7912327711341, 2.7222692512663, 3.40648642432304, 
    3.53308023141906, 2.59532220284315, 2.3166708613396, 2.66098456839415, 
    2.62819739311836), `100033414_at` = c(3.79468365910661, 3.34649962857668, 
    4.29971184424969, 3.81085169542991, 3.75804439679994, 3.81895258294878, 
    4.03594900960396, 3.72128838403612, 3.08893951742897, 3.82989979044012, 
    3.00837233455368, 3.80555080463427, 3.29585327836005, 3.18666418416018, 
    3.27434364943932), `100033418_at` = c(2.84818282222582, 2.29546377029219, 
    2.48325694938049, 3.2386968734862, 2.50164870297228, 2.72080210986981, 
    2.58058159047299, 2.38231438864918, 2.53998515102438, 2.53965338068817, 
    3.53116849547884, 2.58851750945952, 2.1940368933459, 2.34397350375656, 
    2.39335155022896)), row.names = c("Tarca_001_P1A01", "Tarca_003_P1A03", 
"Tarca_004_P1A04", "Tarca_005_P1A05", "Tarca_006_P1A06", "Tarca_007_P1A07", 
"Tarca_008_P1A08", "Tarca_011_P1A11", "Tarca_012_P1A12", "Tarca_013_P1B01", 
"Tarca_015_P1B03", "Tarca_016_P1B04", "Tarca_017_P1B05", "Tarca_018_P1B06", 
"Tarca_019_P1B07"), class = "data.frame")

我的尝试

pca <- prcomp(my_df[, -c(1:6)])
dat <- cbind(my_df[, c(1:6)], pca$x[, 1:5])

library(plotly)
library(dplyr)
library(RColorBrewer)
age_group = 10
dat %>% 
  mutate(group = paste(Batch, Platform, "age", 
                       floor(GA/age_group)*age_group, "-", 
                       floor(GA/age_group)*age_group + age_group - 1)) %>%
plot_ly(x = ~GA, y = ~Set, z = ~Platform, color = ~group) %>%
  add_markers(marker = list(size = 2,
                            color = colorRampPalette(brewer.pal(11,"Spectral"))(10))) %>%
  layout(scene = list(xaxis = list(title = "GA"),
                      yaxis = list(title = "Set"),
                      zaxis = list(title = "Platform")))

所需的情节

我期望3D散点图如下所示:

enter image description here

通过继续上述尝试,如何获得3d散点图?有什么想法可以在R中完成吗?谢谢

新更新

我通过使用实际数据使用了@TobiO解决方案(我从this thread中添加了手动颜色),但是对于我来说似乎很难理解。我们如何优化绘图?

enter image description here

1 个答案:

答案 0 :(得分:1)

我也曾经尝试过许多不同的方法来获得与您的图片相似的情节。我发现rgl和汽车库最合适。 怎么样:

dat=dat %>% #make grouping part of data frame
  mutate(group = paste(Batch, Platform, "age", 
                       floor(GA/age_group)*age_group, "-", 
                       floor(GA/age_group)*age_group + age_group - 1) %>% factor)

dat$colors=color=brewer.pal(length(levels(dat$group)),"Paired")[as.numeric(dat$group)] #add colors (in your call, there seem too few colors defined)
mycolorscheme=unique(dat$colors)
names(mycolorscheme)=unique(dat$group) #have this as a named vector

library(car)
library(rgl)
open3d()
scatter3d(x = dat$PC1, y = dat$PC2, z = dat$PC3,
                      groups = dat$group,
                      grid = T, surface = F,ellipsoid = T,surface.col =mycolorscheme,
                      xlab="PC1",ylab="PC2",zlab="PC3")
texts3d(x = dat$PC1, y = dat$PC2, z = dat$PC3,
       groups = dat$group,texts=dat$group, pos=2,color=mycolorscheme,adj=0)

在您的示例数据集中,组是如此之小,以至于绘制这些椭圆存在问题,这会给定位文本标签带来麻烦。 car::Identify3d

中还提供了一个交互式版本。