ggplot_colour palette error. Insufficient values in manual scale. 6 needed but only 3 provided

250 Views Asked by At

Unable to get plots to print - asking for Error in palette(): ! Insufficient values in manual scale. 6 needed but only 3 provided. Run rlang::last_trace() to see where the error occurred.

Code that i’m running

Data = read.csv("S1_tp plots_BSF.csv")
require(Rmisc)
require(ggplot2)
require(grid)
theme_bw()
library(gridExtra)
require(gridExtra)
library(devtools)
require(devtools)
devtools::install_github("wilkelab/cowplot", force=TRUE)

require(cowplot)
# replacing "tp' with tp
#replacing 'Treatment' with stage.


Datase <- summarySE(Data,na.rm=TRUE, measurevar="tp", groupvars=c("Location","stage","time"))

## Not in this code ## Datase$Site <- factor(Datase$Site, levels=c("1","2","3"))
Datase$stage <- factor(Datase$stage)
## Datase$Treatment <- factor(Datase$Treatment, levels=c("Zero","Five","Ten","Fifteen","Twenty","Ramp"))
Datase$Location<-factor(Datase$Location, labels=c("B0","B5","B10","B15","B20","BR"))
Datase$time<-factor(Datase$time,c("0", "1","2", "3","4", "5","6", "7","8", "10","14"))

B0 = ggplot(Datase[Datase$Location=="B0",], aes(x=time, y=tp,group=(stage),shape = factor(stage))) + scale_shape_manual(name = "",values=c(16,6,5))+ 
  theme_bw()+xlab("")+ylab(expression(paste("Individuals", " ", m^-2,"", sep="")))+theme(axis.text.x = element_blank())+
  geom_line(position=position_dodge(0),size = 0.5)+ theme(text = element_text(size=20))+facet_grid(.~Location, scales="free_y")+ theme(strip.background = element_blank(), strip.text = element_blank()) +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="stage") +
  geom_point(position=position_dodge(0),size = 5)+ theme(text = element_text(size=20))+guides(shape = guide_legend(reverse=F))+ theme(legend.position="none",legend.key.size = unit(0.1, "cm"))+facet_grid(.~Location, scales="free_y")  +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  facet_wrap(~Location) +
  coord_cartesian(ylim=c(0,100))

B5 = ggplot(Datase[Datase$Location=="B5",], aes(x=time, y=tp,group=(stage),shape = factor(stage))) + scale_shape_manual(name = "",values=c(16,6,5))+ 
  theme_bw()+xlab("")+ylab(expression(paste(" ")))+theme(axis.text.x = element_blank())+
  geom_line(position=position_dodge(0),size = 0.5)+ theme(text = element_text(size=20))+facet_grid(.~Location, scales="free_y")+ theme(strip.background = element_blank(), strip.text = element_blank()) +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  geom_point(position=position_dodge(0),size = 5)+ theme(text = element_text(size=20))+guides(shape = guide_legend(reverse=F))+ theme(legend.position="none",legend.key.size = unit(0.1, "cm"))+facet_grid(.~Location, scales="free_y")  +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  facet_wrap(~Location) +
  coord_cartesian(ylim=c(0,100))

B10 = ggplot(Datase[Datase$Location=="B10",], aes(x=time, y=tp,group=(stage),shape = factor(stage))) + scale_shape_manual(name = "",values=c(16,6,5))+ 
  theme_bw()+xlab("")+ylab(expression(paste(" ")))+theme(axis.text.x = element_blank())+
  geom_line(position=position_dodge(0),size = 0.5)+ theme(text = element_text(size=20))+facet_grid(.~Location, scales="free_y")+ theme(strip.background = element_blank(), strip.text = element_blank()) +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  geom_point(position=position_dodge(0),size = 5)+ theme(text = element_text(size=20))+guides(shape = guide_legend(reverse=F))+ theme(legend.position="none",legend.key.size = unit(0.1, "cm"))+facet_grid(.~Location, scales="free_y")  +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  facet_wrap(~Location) +
  coord_cartesian(ylim=c(0,100))

B15 = ggplot(Datase[Datase$Location=="B15",], aes(x=time, y=tp,group=(stage),shape = factor(stage))) + scale_shape_manual(name = "",values=c(16,6,5))+ 
  theme_bw()+xlab("")+ylab(expression(paste(" ")))+theme(axis.text.x = element_blank())+
  geom_line(position=position_dodge(0),size = 0.5)+ theme(text = element_text(size=20))+facet_grid(.~Location, scales="free_y")+ theme(strip.background = element_blank(), strip.text = element_blank()) +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  geom_point(position=position_dodge(0),size = 5)+ theme(text = element_text(size=20))+guides(shape = guide_legend(reverse=F))+ theme(legend.position="none",legend.key.size = unit(0.1, "cm"))+facet_grid(.~Location, scales="free_y")  +geom_errorbar(position=position_dodge(0),aes(ymin=tp-se,ymax=tp+se),width=.1,colour="black") +
  facet_wrap(~Location) +
  coord_cartesian(ylim=c(0,100))


B15 <- B15 + guides(shape=guide_legend(override.aes=list(size=6)))
A <-gridExtra::grid.arrange(B0,B5,B10,B15, ncol=3)  

I have tried the following final output....

A <-gridExtra::grid.arrange(B0,B5,B10,B15,ncol=3)  

and was expecting four plots to be printed 3 x 2.

The following message was returned.

> A <-gridExtra::grid.arrange(B0,B5,B10,B15, ncol=3)  
Error in `palette()`:
! Insufficient values in manual scale. 6 needed but only 3 provided.
Run `rlang::last_trace()` to see where the error occurred.

Some help getting these survival plots printed would be very much appreciated. Needed for seminar at the end of the week and final thesis. Thank you.

0

There are 0 best solutions below