'ggthemes scale_colour_solarized("blue") gives "Error in [[: subscript out of bounds" when applied to a plot

plot <-
    ggplot(tot_costs,
           aes(period, total_cost, colour = team, group = team)) +
    geom_point() +
    geom_line() +
    ylab("") +
    xlab("Year") +
    # Commented working code theme_minimal() +
    theme_solarized(light = FALSE, base_size = 16) + scale_colour_solarized("blue") +
    theme(axis.text.x = element_text(angle = 45),
          legend.title = element_blank())

When I replace the theme_solarized by theme_minimal, everything is working, but when I try to apply theme_solarized/scale_colour to the plot, I get a "Subscript out of bounds error". I wonder if it's related to the color palette, maybe there are too many "teams" for the colors available. However, it's the solarized theme is working fine with other plots with the same teams



Solution 1:[1]

In the documentation for scale_color_solarized() it says to:

See solarized_pal() for details.

Looking into ?ggthemes::solarized_pal, it says:

This palette supports up to seven values.

I guess in this case your easiest choice is to use a different color scale.

By the way, distinguishing more than around seven colours can prove difficult if they are close togheter in a plot, so think about giving an additional aesthetic to your team variable (e.g. shape).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ildifa