简体   繁体   English

在 scatterplot3d 的底部绘制很长的图例

[英]Drawing very long legend at the bottom of scatterplot3d

How I can put a very long legend at the bottom of the scatterplot3d plot properly?我如何才能在 scatterplot3d plot 的底部正确放置一个很长的图例? I tried to use layout, oma, mar, but I couldn't figure it out.我尝试使用布局、oma、mar,但我无法弄清楚。 What I want to have is having the plot at the top and putting the legend at the bottom.我想要的是将 plot 放在顶部并将图例放在底部。 I can not proceed further.我不能再继续了。 I really need help:(我真的需要帮助:(

Here is the code I tried so far:这是我到目前为止尝试过的代码:

library("scatterplot3d")


mean_E = c(2.5459233083,-1.75924812,-1.48706767,-1.70857143,-1.7201293233,2.1565954887,-1.3398496,3.353383,-0.96511278,2.81007519,0.8252120301,0.7203008,-1.2539834586,-1.5503759,0.67669,-0.0421053)
mean_P = c(1.02256,-1.744361,-1.56391,0.390977,-0.9819549,1.76015038,-1.962406,2.6294015038,0.526316,2.9744361,0.9172932,0.6315789,-0.6210526,0.93985,1.4208105263,0.406015)
mean_A = c(0.09023,-0.5714,-0.6165414,-0.428571,0.225564,0.80766917,-0.64180451,1.6967218045,-0.030075,2.6631579,0.5714286,0.1609023,-0.7487218,0.3619112782,1.7578947,0.3729323)
statementNameList = c("Sentence Sentence Sentence Sentence Sentence Sentence 1",
"Sentence Sentence Sentence Sentence Sentence Sentence 2",
"Sentence Sentence Sentence Sentence Sentence Sentence 3",
"Sentence Sentence Sentence Sentence Sentence Sentence 4",
"Sentence Sentence Sentence Sentence Sentence Sentence 5",
"Sentence Sentence Sentence Sentence Sentence Sentence 6",
"Sentence Sentence Sentence Sentence Sentence Sentence 7",
"Sentence Sentence Sentence Sentence Sentence Sentence 8",
"Sentence Sentence Sentence Sentence Sentence Sentence 9",
"Sentence Sentence Sentence Sentence Sentence Sentence 10",
"Sentence Sentence Sentence Sentence Sentence Sentence 11",
"Sentence Sentence Sentence Sentence Sentence Sentence 12",
"Sentence Sentence Sentence Sentence Sentence Sentence 13",
"Sentence Sentence Sentence Sentence Sentence Sentence 14",
"Sentence Sentence Sentence Sentence Sentence Sentence 15",
"Sentence Sentence Sentence Sentence Sentence Sentence 16")

mean_df <- data.frame("E"=mean_E,"P"=mean_P,"A"=mean_A,"Sentence"=statementNameList)

expressions <- data.frame("E"=c(-1.569,1.4796,-2.3793,3.4469,-2.4077, 2.8125,-2.5706,  3.0389,-2.09,-2.2676, -2.0267),
                          "P"=c(-1.1345,1.3151,-1.3414,2.9125,-0.7577, 2.2475,0.2676, 1.8417,-0.7833, -0.3514, 1.0667 ),
                          "A"=c(-2.0621,2.3139,-1.8759,0.2438,-0.6808, 2.16,0.4265, -2.7889,-2.19,0.7243,1.7967),
                          "Emotion"= c("Tired", "Surprised", "Sad", "Happy", "Fearful", "Excited", "Disgusted", "Calm", "Bored", "Annoyed", "Angry") )


title="EPA Ratings"
xlabel = "Evaluation (E)"
ylabel = "Potency (P)"
zlabel = "Activitiy (A)"
angle = -70


plot<-scatterplot3d(expressions$E ,expressions$P,expressions$A, main=title,
                    xlab=xlabel, ylab=ylabel, zlab=zlabel, pch = "", grid=TRUE, box=TRUE,
                    angle = angle)
plot$points3d(expressions$E ,expressions$P,expressions$A, pch = 5, col="red")

color_palette = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]
# select different color for each sentence
colors =sample(color_palette, 16)
plot$points3d(mean_df$E ,mean_df$P,mean_df$A, pch = 16, col=colors, cex=2)

legend(3,-3, legend = statementNameList,col = colors, pch = 16, inset = -0.5, cex = 0.7,
        bty = "n",xpd = TRUE)

text(plot$xyz.convert(expressions$E ,expressions$P,expressions$A-0.2), labels = expressions$Emotion, col = "darkblue", cex=0.6)

Here is the current output I have:这是我当前的 output: 在此处输入图像描述

May be you can try below code.也许你可以试试下面的代码。 I found that in this link.我在这个链接中找到了。 http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization

Custom shapes/colors自定义形状/颜色

s3d <- scatterplot3d(iris[,1:3], pch = shapes, color=colors)
legend("bottom", legend = levels(iris$Species),
      col =  c("#999999", "#E69F00", "#56B4E9"), 
      pch = c(16, 17, 18), 
      inset = -0.25, xpd = TRUE, horiz = TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM