Q:

Don't know how to add o to a plot with R package dbplot

I'm trying to add a legend to a boxplot which I created with the R-package dbplot. Unfortunately I'm getting the error:
"Don't know how to add o to a plot"

Here is my sample code: (I've added sample data but I load the data from a spark table!)
cars <- c(27,37,9,11,47,29,39,41,18,30)
cars_s <- c(0,99,10,0,0,0,0,0,10,10)
sample_data <- data.frame(cars, cars_s)

sparkTable %>% 
   filter(cars > -1) %>% 
   dbplot_boxplot(x = cars_s, var = cars, coef = 1.5) +
   ggtitle("Boxplot Title") +
   labs(x = "status", y = "cars") +
   legend("topright", inset = .05, title = "Status", legend = as.character(c("0", "1", "2"))) + 
  theme_bw()

The output of my boxplot looks like this without the legend line

As described, I'm not able to add a legend.

A:

This is because dbplot_boxplot() in dbplot doesn't support legends. 
If it were an ordinary data.frame you would just add color = x:
  library(tidyverse)
  mtcars %>% 
    mutate(cyl = as.factor(cyl)) %>% 
ggplot(aes(x = cyl, y = mpg, color = cyl)) +
  geom_boxplot()

Created on 2019-05-07 by the reprex package (v0.2.1.9000)
However, when working with a database you always have to compute in the database and then collect into memory in R. dbplot is a package that does this and the plotting for you. Now, boxplots are a bit special because you have to compute a number of columns such as quartiles, inter range quartiles and so on. So to do it by hand may be a bit hefty, since the legend won't add any necessary information in your case. 
However, if you think the package should add this feature you can leave a feature request as an issue on the package's Github: https://github.com/edgararuiz/dbplot/issues 

