Scale_x_manual error (extra point on legend)

435 views
Skip to first unread message

Michael Caruso

unread,
Jul 13, 2015, 12:06:59 PM7/13/15
to ggp...@googlegroups.com
When I run this script I am receiving an error: 

ca1.gr=ggplot(ihc,aes(Latency,CA1.GR.ir, group=Arena))+
  geom_smooth(aes(fill=Arena, color=Arena),method="lm",se=FALSE,size=1)+
  geom_point(aes(shape=Arena, fill=Arena, color=Arena),size=3.5)+ # add a scatter plot; constant size, shape/fill depends on stress condition
  scale_x_continuous("Z-Score for Mean Latency to Approach Novelty (PND 70)",
                     limits=c(-3.5,3.5), 
                     breaks=seq(-3,3,by=1))+
   scale_y_continuous((expression(paste('Hippocampus CA1 GR+ cells /  ', mm^{2}))),
                     limits=c(5,10),
                     breaks=seq(5,10,by=1))+ 
  ggtitle('Figure 6a.')+
  scale_shape_manual(name="Exploration Arena",
                     breaks=c("Novel Physical", "Novel Social"),
                     labels=c("Novel Physical", "Novel Social"),
                     values=c(21, 24))+ # explicitly have fillable shapes for each group
  scale_fill_manual(name="Exploration Arena",
                    breaks=c("Novel Physical", "Novel Social"),
                    labels=c("Novel Physical", "Novel Social"),
                    values=c("red","black"))+
  scale_color_manual(name="Exploration Arena",
                     breaks=c("Novel Physical", "Novel Social"),
                     labels=c("Novel Physical", "Novel Social"),
                     values=c("red","black"))+
  theme_bw()+
  theme(plot.title = element_text(face="bold", size=24, vjust=2, hjust=-0.1), #use theme_get() to see available options
        axis.title.x = element_text(size=24, vjust=-0.5),
        axis.title.y = element_text(face="bold", size=24, vjust=1.0, angle=90),
        axis.text.x =  element_text(size=20),
        axis.text.y = element_text(size=20),
        panel.border = element_rect(size = 0.5, colour = "black"),
        panel.grid.major = element_blank(), # switch off major gridlines
        panel.grid.minor = element_blank(),
        legend.justification = c(1,1),
        legend.position = c(1,1), # manually position the legend (numbers being from 0,0 at bottom left of whole plot to 1,1 at top right)
        legend.title = element_text(face="bold", size=15), 
        legend.text = element_text(size=15),
        legend.key.size = unit(1.0, "lines"),
        legend.key = element_blank()) # switch off minor gridlines  


Error message = 
Error: Insufficient values in manual scale. 3 needed but only 2 provided.
In addition: Warning messages:
1: Removed 17 rows containing missing values (stat_smooth). 
2: Removed 17 rows containing missing values (stat_smooth).

The additional warnings are ok because they don't affect my figure. However, the manual scale thinks I need 3 values when there are only two in the data set. Any idea why this is happening?

Thank you,
Mike
Reply all
Reply to author
Forward
0 new messages