I'm writing a package with plot methods for the classes defined in it. When designing these plot methods, I figured out I could use ggplot2
functions and have these plot methods to transform the objects suitably and return a ggplot
object, so users could benefit from all the flexibility ggplot2
provides.
On the other hand, if the user doesn't want/know ggplot2
at all, just using the method should result in a decent visualization.
My questions are about what are the best practices in these situations:
- Should I just import
ggplot2
and have the user load it if/when he wants to modify the "standard" visualization produced in the method or add it to theDepends
field? Note that visualization is not the main purpose. - This "standard" plot method requires modifying some of the scales (e.g. the standard color scale is not good for the problem), so I add appropriate scale layers in the function definition. The problem is: when the user overwrites these scales (and I really wanted ggplot's flexibility so they're able to do it if they want to), it throws a warning
Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.
that will surely confuse the user. Is there a way to get rid of this warning? Is there a better approach here?
Example:
plot(myclass) + scale_fill_brewer()