greg holly
2019-Jan-23 23:12 UTC
[R] Error "sufficient values in manual scale. 10 needed but only 7 provided"
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]]
Jeff Newmiller
2019-Jan-24 00:46 UTC
[R] Error "sufficient values in manual scale. 10 needed but only 7 provided"
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 at 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 at 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.
greg holly
2019-Jan-24 03:43 UTC
[R] Error "sufficient values in manual scale. 10 needed but only 7 provided"
Hi Jeff; I figured out the problem. I do apologize to you and members in the list to bother you with this simple problem. Regards, Greg On Wed, Jan 23, 2019 at 6:46 PM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> 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 at 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 at 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. >[[alternative HTML version deleted]]