How to deal with dark areas of R perspective plot -


i'm having strange problem persp() function inside r. i'm using split.screen()function arrange 3 plots. i've produced mwe below:

f <- function(x,y) {   return(x*y) }  u <- seq(0,5, = 0.1) v <- seq(0,5, = 0.1) z <- outer(u, v, f)  persp(u,v,z, ticktype="detailed", col = rgb(0.2,0.6,1))  pdf("~/desktop/test.pdf", width = 10, height = 10) # adjust path necessary split.screen( figs = c( 2, 1 ) ) split.screen( figs = c( 1, 2 ) )  screen(2) persp(u,v,z, ticktype="detailed", col = rgb(0.2,0.6,1))  screen(3, new = false) persp(u,v,z, ticktype="detailed", col = rgb(0.2,0.6,1))   screen(4, new = false)  persp(u,v,z, ticktype="detailed", col = rgb(0.2,0.6,1))  close.screen(all = true) dev.off() 

looking @ resulting pdf, surfaces quite dark, in left side. when print file darker (too dark).

i've attached screenshot of plot zoom of 1 of 3 plots in rstudio. looks better. i'd 3 plots plot zoom in rstudio, when printed.

does know how that?

cheers!

dark

enter image description here

you're seeing effect of gridlines being closer in smaller versions of plot. if shrink graph created rstudio's zoom down same size other graphs, looks dark ones created pdf device. problem gridlines appear close due foreshortening @ low viewing angles (for example, corner of plots). can see if zoom in on plot:

enter image description here

here options improve output:

  1. reduce line width finer gridlines. increase relative area of blue squares, making whole surface appear brighter, , particularly reduce darkening in far corner due "bunching up" of grid lines result of shallow viewing angle.

    persp(u,v,z, ticktype="detailed", col = rgb(0.2,0.6,1), lwd=0.5) 

    i found pdf device didn't seem act on lwd argument, cairo_pdf device (although gridlines still come out thicker appear in rstudio graphics window). lwd=0.5 worked viewing in rstudio graphics window (and output png file). cairo_pdf output, lwd=0.1 resulted in thinner lines default linewidth, not thin have liked. however, when set linewidth lower 0.07, no plot appeared @ all. here's same plot above, linewidth set 0.1 , using rstudio's pdf output:

    enter image description here

  2. reduce number of gridlines using larger value of by in seq functions.

  3. use brighter color perspective surface.

  4. use lighter color gridlines (e.g., set border="gray40" or border="white" in persp function).

for example, here's result of following call persp. background color little brighter , gridlines thinner , white instead of black:

png("~/persp.png", 500,500) persp(u,v,z, ticktype="detailed", col=hcl(240,100,80), border="white", lwd=0.5) dev.off() 

enter image description here


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -