ggthemes icon indicating copy to clipboard operation
ggthemes copied to clipboard

Allow Gradient Scales to Accept Midpoint Arg

Open alex-gable opened this issue 2 years ago • 0 comments

Instead of calling continuous_scale, scale_*_gradient_{theme} should call the appropriate ggplot2::scale_*_gradient function.

for example, ggplot::scale_fill_gradient2() includes the midpoint argument (and default), which it passes to continuous_scale()'s rescaler..

> scale_fill_gradient2
function (..., low = muted("red"), mid = "white", high = muted("blue"), 
    midpoint = 0, space = "Lab", na.value = "grey50", guide = "colourbar", 
    aesthetics = "fill") 
{
    continuous_scale(aesthetics, "gradient2", div_gradient_pal(low, 
        mid, high, space), na.value = na.value, guide = guide, 
        ..., rescaler = mid_rescaler(mid = midpoint))
}

this is very similar to - and possibly redundant with - what I see in scale_fill_gradient2_tableau()

> ggthemes::scale_fill_gradient2_tableau
function (palette = "Orange-Blue Diverging", ..., na.value = "grey50", 
    guide = "colourbar") 
{
    continuous_scale("fill", "tableau2", tableau_div_gradient_pal(palette), 
        na.value = na.value, guide = guide, ...)
}

while this same functionality could be implemented in manually, it seems to me to be more appropriate and intuitive that a function like scale_fill_gradient2_tableau would extend scale_fill_gradient2 which extends continuous_scale

alex-gable avatar Dec 30 '21 02:12 alex-gable