0

I used the below code to do 3D PCA, all I want to make a 3D box plot.

Mydata = read.csv("PCA.csv")
head(Mydata)
pca = prcomp(Mydata[,6:11], scale. = TRUE)
summary(pca)
library(pca3d)
gr = factor(Mydata[,1])
pca3d(pca, group = gr)
dput(Mydata)
pca3d(pca,title = "Nanjing", axes.color= "black",group=gr, show.ellipses=TRUE,
      ellipse.ci=0.95,biplot=TRUE, biplot.vars=3, show.centroids= TRUE,show.group.labels=FALSE, show.plane=FALSE, legend = "topleft")

To download the image I used

snapshotPCA3d(file="Nanjing.png")

but it didn't work, it is showing a warning text which I didn't understand (look below)

Warning messages: 1: In rgl.snapshot(filename = file, fmt = "png", top = TRUE) : RGL: PNG Pixmap Saver Warning: Image width is zero in IHDR 2: In rgl.snapshot(filename = file, fmt = "png", top = TRUE) : RGL: PNG Pixmap Saver Warning: Image height is zero in IHDR 3: In rgl.snapshot(filename = file, fmt = "png", top = TRUE) : RGL: PNG Pixmap Saver Error: Invalid IHDR data 4: In rgl.snapshot(filename = file, fmt = "png", top = TRUE) : RGL: PNG Pixmap Saver Error: an error occured 5: In rgl.snapshot(filename = file, fmt = "png", top = TRUE) : 'rgl.snapshot' failed

Data I used

structure(list(Location = c("Ningde Coastal Area", "Ningde Coastal Area", 
"Ningde Coastal Area", "Ningde Coastal Area", "Ningde Coastal Area", 
"Ningde Coastal Area", "Ningde Coastal Area", "Ningde Coastal Area", 
"Ningde Coastal Area", "Ningde Coastal Area", "Ningde Coastal Area", 
"Ningde Coastal Area", "Ningde Coastal Area", "Ningde Coastal Area", 
"Ningde Coastal Area", "Ningde Coastal Area", "Ningde Coastal Area", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay"), Serial = c(14L, 15L, 17L, 18L, 19L, 20L, 21L, 
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 
48L, 49L, 50L, 51L, 52L), Station = c("NDDZ031", "NDDZ034", "NDDZ035", 
"NDDZ041", "NDDZ046", "NDDZ048", "NDDZ050", "NDDZ055", "NDDZ058", 
"NDDZ065", "NDDZ066", "NDDZ068", "NDDZ072", "NDDZ073", "NDDZ074", 
"NDDZ080", "NDDZ082", "NDDZ91", "NDDZ92", "NDDZ94", "NDDZ95", 
"NDDZ96", "NDDZ97", "NDDZ98", "NDDZ99", "NDDZ103", "NDDZ105", 
"NDDZ106", "NDDZ107", "NDDZ112", "NDDZ113", "NDDZ114", "NDDZ115", 
"NDDZ116", "NDDZ117", "NDDZ119", "NDDZ122", "NDDZ123"), Longitude = c(119.8156314, 
119.8109757, 119.9013884, 120.1667206, 120.0796901, 119.7829741, 
119.9602213, 119.7401038, 120.1113902, 119.7060803, 120.1239972, 
119.7798066, 120.0968136, 119.7086703, 119.7827459, 120.0751752, 
120.0621476, 119.6875, 119.6641667, 119.7163889, 119.7425, 119.69, 
119.7719444, 119.6622222, 119.7544444, 119.6644444, 119.6875, 
119.7369444, 119.7672222, 119.6583333, 119.6327778, 119.5991667, 
119.6769444, 119.7019444, 119.7419444, 119.6216667, 119.6722222, 
119.6408333), Latitude = c(26.48095232, 26.51638163, 26.53300528, 
26.54343039, 26.56656159, 26.59238665, 26.6023812, 26.62635719, 
26.64614884, 26.70021888, 26.70684282, 26.72669529, 26.75513142, 
26.77262578, 26.7665767, 26.82756691, 26.6238606, 26.34944444, 
26.35972222, 26.36, 26.36027778, 26.37583333, 26.38277778, 26.38638889, 
26.39277778, 26.41055556, 26.41972222, 26.42833333, 26.42861111, 
26.43361111, 26.44416667, 26.45, 26.45, 26.44805556, 26.44805556, 
26.46638889, 26.47166667, 26.4775), MPs = c(101.1310963, 126.7889088, 
85.74767297, 153.5234525, 51.35979247, 42.82041038, 214.4548942, 
96.9063435, 155.5864259, 46.01889546, 97.50099786, 78.36325034, 
161.375366, 99.76091135, 59.82528502, 98.7524581, 110.3141717, 
89.08, 103.02, 89.61, 106.42, 36.85, 66.93, 81.39, 152.58, 171.61, 
105.34, 148.31, 293.68, 279.4, 248.44, 273.39, 131.06, 36.33, 
29.62, 89.07, 382.31, 170.27), Petrolium = c(26.41089103, 5.575674479, 
112.1713291, 15.76231172, 28.05251105, 15.56603488, 34.78641497, 
20.95268019, 11.97087574, 28.16452888, 45.10068937, 32.00209717, 
1.098327442, 195.4523585, 94.0545153, 20.3648651, 19.08090108, 
20.26723856, 35.12860786, 38.00639611, 485.9158071, 6.801285888, 
130.2613429, 26.41691724, 21.47363409, 75.24255785, 9.088017875, 
17.83869051, 106.4365614, 367.7372615, 26.95847112, 42.01753212, 
17.56582294, 72.00256098, 382.5705508, 150.0004825, 452.8679126, 
61.51137016), Sulfide = c(5.19, 0, 72.82, 19.49, 2.93, 0, 43.95, 
1.37, 23.27, 12.19, 35.69, 77.05, 4.03, 65.29, 55.12, 29.95, 
14.93, 15.16, 47.67, 30.23, 75.05, 10.51, 38.75, 21.64, 35.97, 
122.53, 6.95, 58.52, 75.92, 92.23, 10.85, 72.1, 28.46, 81.19, 
195.59, 42.54, 277.4, 81.67), PCB = c(5.76, 1.44, 8.84, 11.92, 
3.4, 17.08, 0.56, 10.56, 5.24, 1.96, 6.44, 9.44, 10.28, 12.92, 
14.52, 0, 7.84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0), PAH = c(23.36922085, 24.88374369, 21.49366333, 
25.69248678, 27.47334181, 36.56726931, 478.4803895, 39.12822287, 
17.2462056, 29.30102312, 232.0038657, 98.88904227, 22.6525315, 
31.41940388, 29.73926409, 36.20400715, 28.34097634, 0.0479, 0.0638, 
0.1312, 0.1293, 0.0589, 0.1032, 0.2725, 0.0712, 0.1173, 0.0703, 
0.2097, 0.1261, 0.0685, 0.0796, 0.1353, 0.0354, 0.0323, 0.034, 
0.0269, 0.0952, 0.0269), OCP = c(0.165265157, 0.004517346, 0.417073616, 
2.155375191, 0, 23.48084273, 0, 2.096700845, 1.852219063, 0.074522052, 
0.694281604, 0.112198511, 0.171174141, 4.644606351, 0.969985822, 
1.942156359, 2.36619641, 0.01071845, 0, 0, 0, 0, 0.004247812, 
0, 0, 0, 0.002020821, 0, 0.055799207, 0.003690873, 0.019063717, 
0, 0.173323781, 0.010429405, 0, 0, 0.013486877, 0)), class = "data.frame", row.names = c(NA, 
-38L))
                    
Kazi
  • 67
  • 7
  • [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. Without any of your data, we can't run your code, and we can't see any of the output you're trying to change – camille May 24 '21 at 15:03

1 Answers1

0

I used this code and it works:

rgl.snapshot(filename = "PCA7gr.png",fmt="png",webshot2=TRUE)
Dharman
  • 30,962
  • 25
  • 85
  • 135
JamBelg
  • 60
  • 5