Home > front end >  Inconsistent polygon behavior using transparent colors
Inconsistent polygon behavior using transparent colors

Time:12-12

I was trying to draw a partially transparent polygon recently (something I've done many times in the past) and discovered inconsistent behavior where, under certain conditions, the polygon fill color will not be drawn.

Running the following code, the third and fourth polygon chunks will work, but the first two will not (if you change border from NULL to a color, the border will draw just fine, but the fill will not).

var1 = c(10.13981, 11.47067, 11.07515, 11.32449, 11.57041, 11.75539, 10.81107, 10.90303, 10.47502,
         10.90169, 11.38179, 10.05446, 10.72442, 10.68973, 12.31730, 13.16385, 12.02199, 10.91423,
         11.54465, 10.80909)

var2 = c(116.0, 100.0, 117.0, 116.0, 112.0, 125.5, 110.0, 103.0,  94.0, 105.0, 97.0, 131.0, 108.5,  95.0, 96.0,  78.0,  89.0, 103.0,  99.0,  90.0)

plot(var2~var1)

#What I want to draw
polygon(
  x = c(seq(9,15,0.1), rev(seq(9,15,0.1))),
  y = c(rep(120,61), rep(100,61)),
  col = adjustcolor(col = 'grey', alpha.f = 0.5),
  border = NA
)

#checking if replacing "adjustcolor" with the output of the function works
polygon(
  x = c(seq(9,15,0.1), rev(seq(9,15,0.1))),
  y = c(rep(120,61), rep(100,61)),
  col = "#BEBEBE1A",
  border = NA
)

#works just fine if alpha.f is set to 1 (fully opaque)
polygon(
  x = c(seq(9,15,0.1), rev(seq(9,15,0.1))),
  y = c(rep(120,61), rep(100,61)),
  col = adjustcolor(col = 'grey', alpha.f = 1),
  border = NA
)

#works just fine with transparency using different x/y values
polygon(
  x = c(11,11,12,12),
  y = c(110,120,120,110),
  col = adjustcolor(col = 'grey', alpha.f = .1),
  border = NA
)

Essentially, certain combinations of x/y variables and alpha.f values will cause the polygon fill to just not work.

This makes no sense whatsoever to me. Am I missing something obvious? This is driving me crazy.

adding screenshots of my outputs using the various polygon codes (changed all borders to 'black'):

#1enter image description here

#2 enter image description here

#3enter image description here

#4enter image description here

CodePudding user response:

Upon searching the enter image description here

edit: oh just realized that you've also found the bug description.

  •  Tags:  
  • r
  • Related