yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.39k stars 878 forks source link

3D scatter plots not showing labels #760

Closed jrowen closed 10 years ago

jrowen commented 10 years ago

When a large number of points are added to 3D scatter plot, point labels come through as black rectangles when html document is viewed in Chrome 34.


---
output:
  html_document:
    self_contained: no

---
```{r setup, results='asis'}
library(knitr)
knit_hooks$set(webgl = hook_webgl)
cat('<script type="text/javascript">', readLines(system.file('WebGL', 'CanvasMatrix.js', package = 'rgl')), '</script>', sep = '\n')

This works fine.

x <- sort(rnorm(100))
y <- rnorm(100)
z <- rnorm(100) + atan2(x,y)
plot3d(x, y, z, col=rainbow(100))
text3d(x, y, z, text=c(rep("", 90), LETTERS[1:10]))

This shows black boxes.

x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
text3d(x, y, z, text=c(rep("", 990), LETTERS[1:10]))
yihui commented 10 years ago

Thanks! I can reproduce it under Ubuntu and Chrome 34, but this is not a knitr issue, so I cannot do much about it. Please report to the maintainer of rgl (http://cran.rstudio.com/package=rgl), with this minimal example:

library(rgl)
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
text3d(x, y, z, text=c(rep("", 990), LETTERS[1:10]))
writeWebGL()
jrowen commented 10 years ago

The bug appears to be with webGL. For anyone who may also run into this problem, splitting the text3d call into smaller chucks appears to work. Thanks for looking into the problem.

library(rgl)
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
splt <- split(seq_along(x), ceiling(seq_along(x)/100))
for(i in splt)
  text3d(x[i], y[i], z[i], text=rep("A", 1000)[i])
writeWebGL()
yihui commented 10 years ago

Great. Thanks for sharing the solution!

github-actions[bot] commented 4 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.