[R] Error "sufficient values in manual scale. 10 needed but only 7 provided"

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Thu Jan 24 01:46:41 CET 2019


Problem is in your data not matching your values, but you did not share your data. Try using the unique() function to see what values you have in your data.

I will say that when I want to assign discrete colors I always start by converting my character column in the data frame to a factor and specify the order I want to see the levels presented in that conversion step. Then the colors only need to be specified in that same order and I don't need to keep repeating the labels in multiple places.

library(ggplot2)

mpg$classf <- factor( mpg$class
                   , levels = c( "2seater"
                               , "subcompact"
                               , "compact"
                               , "midsize"
                               , "minivan"
                               , "suv"
                               , "pickup" 
                               ) 
                   )

class_colours <- rainbow( length( levels( mpg$classf ) ) )
ggplot( mpg, aes( x = classf, y = cty, colour=classf ) ) +
 geom_boxplot() +
 scale_colour_manual( name="Class", values = class_colours )




On January 23, 2019 3:12:26 PM PST, greg holly <mak.hholly using gmail.com> wrote:
>Hi Dear all;
>
>I am getting the "sufficient values in manual scale. 10 needed but only
>7
>provided." problem when running the followings. Your help is highly
>appreciated.
>
>Regards,
>Greg
>
>p2<-p1+scale_color_manual(name="Diseases",
>labels=c("Myocardial Infarction", "Coronary artery disease", "Stroke",
>"Hypertension", "Depression Anxiety Emotional Problems",  "Circulatory
>Problems", "Diabetes"),
>
>values=c("Myocardial Infarction"="red",  "Coronary artery
>disease"="purple","Stroke"="darkgreen",
> "Hypertension"="orange",  "Depression Anxiety Emotional
>Problems"="darkblue",
> "Circulatory  Problems"="darkred","Diabetes"="blue"))
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list