rgl: low resolution legend

你说的曾经没有我的故事 提交于 2019-12-25 00:27:32

问题


Hi guys,

I'm using rgl and shinyrgl to produce a 3D PCA plot within my Shiny app. I'm then using the legend3dfunction to create the legend. As you can see from the image above, the legend is significantly lower resolution than the plot. Has anyone else experienced this problem?

I've included the code being used to draw this below. Since it's Shiny it is a little difficult to produce a full working example. I'm more looking to see if anyone else has fixed this problem.

Matt

UI

      tabItem(tabName = "3DTab",
          fluidRow(
            column(6, 
                   rglwidgetOutput(outputId = "TDPCA")),
            column(6,
                   box(title = "Customisation",
                       width = NULL,
                       collapsible = TRUE,
                       selectizeInput(inputId = "TDPCAClass",
                                      label = "Class",
                                      choices = c("Day"))))

Server

  output$TDPCA <- renderRglwidget({
plot3d(x = TDPCA()$PC1, y = TDPCA()$PC2, z = TDPCA()$PC3, col = TDPCA()[[input$TDPCAClass]],
       xlab = paste("PC1", "-", TDPCA.var()["PC1"], "%"), ylab = paste("PC2", "-", TDPCA.var()["PC2"], "%"), zlab = paste("PC3", "-", TDPCA.var()["PC3"], "%"), type = "p")
       legend3d("topright", 
         legend = c("Monday", "Tuesday", "Wednesday", "Thursday", "Saturday"),
         pch = 16,
         col = palette("default"),
         cex=0.65, inset=c(0))
rglwidget()
})

回答1:


Yes, that issue is mentioned in the help page for legend3d. The problem is that the legend is generated for the current rgl window size, which may be resized later. You want to generate it after resizing.

I'm not quite sure if you can query Shiny about what size the rgl window will be rendered at, but one possibility is just to guess, e.g.

  output$TDPCA <- renderRglwidget({
plot3d(x = TDPCA()$PC1, y = TDPCA()$PC2, z = TDPCA()$PC3, col = TDPCA()[[input$TDPCAClass]],
       xlab = paste("PC1", "-", TDPCA.var()["PC1"], "%"), ylab = paste("PC2", "-", TDPCA.var()["PC2"], "%"), zlab = paste("PC3", "-", TDPCA.var()["PC3"], "%"), type = "p")
       par3d(windowRect = c(0, 0, 512, 512))
       legend3d("topright", 
         legend = c("Monday", "Tuesday", "Wednesday", "Thursday", "Saturday"),
         pch = 16,
         col = palette("default"),
         cex=0.65, inset=c(0))
rglwidget()
})

Edited to add: This page https://groups.google.com/forum/#!topic/shiny-discuss/ZmuZbQfJstg talks about setting the size dynamically.



来源:https://stackoverflow.com/questions/48562604/rgl-low-resolution-legend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!