Search code examples
rggplot2violin-plot

geom_violin - "Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow) : invalid hex digit in 'color' or 'lty'"


I've tried to find a solution to my problem but I couldn't.

I want to plot geom_violin with draw_quantiles c(0.25, .50, .75), but it returns this error:

"Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow) : invalid hex digit in 'color' or 'lty"

The code that triggers the error is the following:

p4 <- p3 +  
  geom_violin(data = Data_Set[-c(1:5), ], 
              aes(x = Per_Set, y = Sales, group = Per_Set),
              fill = NA,  colour = "darkgrey", 
              draw_quantiles = c(0.25, 0.50, 0.75)) + 
  coord_cartesian(ylim = c(0, 
                           max(Var_Comp1, Var_Comp2, Var_Comp3)))

If I run the same code without draw_quantiles = c(0.25, 0.50, 0.75)), it works :

p4 <- p3 + 
  geom_violin(data = Data_Set[-c(1:5), ], 
              aes(x = Per_Set, y = Sales, group = Per_Set),
              fill = NA,  colour = "darkgrey")  + 
              coord_cartesian(ylim = c(0, 
                                       max(Var_Comp1, Var_Comp2, Var_Comp3)))

If I run the same code with draw_quantiles = c(0.25, 0.50, 0.75)) but without + coord_cartesian(ylim = c(0, max(Var_Comp1, Var_Comp2, Var_Comp3))) it doesn't work:

p4 <- p3 +
  geom_violin(data = Data_Set[-c(1:5), ], 
              aes(x = Per_Set, y = Sales, group = Per_Set), 
              fill = NA, colour = "darkgrey", 
              draw_quantiles = c(0.25, 0.50, 0.75))

Same message error than before:

"Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow) : invalid hex digit in 'color' or 'lty"

Could anyone give me a hand with this? I don't know what "color" or "lty" (line type) got to do with this.

ps. p3 has geom_lines and geom_points and there is no NA in the Data_Set. The y axis is formatted as date in R.


Solution

  • I am seeing this error message too ... its a bug that occurs when geom_violin can't calculate quantiles for draw_quantiles = c(...).

    What I did to work around it is to make sure that each violin had at least 8 data points, which was enough to calculate the 6 quantiles I was looking for c(.05, .25, .5, .75, .95, .99) without throwing out an NA or some kind of error that grid.Call.graphics chokes on.