-1

I have created a plot in ggplot2 (see below). I have not figured out how to change the colours to grayscale (Transplanted = yes or no, colours should be black and dark grey) with a black border around the symbols. This would include both the symbols and error bars and should apply to the legend as well.

How to put a black border around the symbols? I tried adding pch=21 to the geomplot line, but that screwed up the colours.

Here is the code for the plot:

# create personal theme for ggplot
my_theme<- theme_grey() + theme(legend.key = element_blank(),axis.text=element_text(size=14),axis.text=element_text(size=14),
                axis.title=element_text(size=16,face="bold"),legend.text = element_text(size = 14),
                legend.title = element_text(size = 16,face="bold"),legend.position="right",panel.grid.major.x = element_blank(),
                strip.text = element_text(size = 15),plot.title = element_text(size = 14, face="bold"))
# create plot
ggplot(data=trans_X,aes(x=Location, y=pred,group= Substrate)) + 
  geom_line(aes( linetype= Substrate,group=Substrate),size=1)+
  geom_point(data=trans_X, aes(shape=transferred, group= transferred,fill=transferred,color=transferred),size=6)+
  geom_errorbar(data=trans_X, position=position_dodge() ,aes(ymin=pred-2*sd,ymax=pred+2*sd, color=transferred),size=0.51,width=0.1)+
  my_theme+ 
  scale_fill_discrete(name="Transplanted")+
  scale_color_manual(name="Transplanted", values = c("no" = "gray10","yes" = "gray40"))+
  scale_shape_discrete(name="Transplanted")+
  scale_linetype_manual(name="Wrackbed substrate",
                        breaks=c("Steninge","M\366lle","K\344mpinge","K\u00E5seberga"),
                        values=c(1,5,3,6))+
  labs(y="Predicted mean development time",x="Fly origin")

enter image description here

Keith W. Larson
  • 1,543
  • 2
  • 19
  • 34
  • 2
    `?scale_color_grey`? – Jaap Mar 15 '16 at 16:17
  • Yes, I have tried that but I get an error telling me that the colour has already been set. Can you give me an example modifying my code? Thanks! – Keith W. Larson Mar 15 '16 at 16:18
  • 1
    I think it is completely lame to give a -1 without a comment? I am trying hard to create a nice plot and look at my code! – Keith W. Larson Mar 15 '16 at 16:37
  • 1
    Probably someone downvoted (not me!) because you didn't include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) in your question. – Jaap Mar 15 '16 at 17:45
  • Sometimes sample data is critical, I just thought that some ggplot guru would see right through my code quite easily. I often spend hours and days tweaking plots because I am in R infrequently! – Keith W. Larson Mar 15 '16 at 18:01
  • 2
    This isn't a one liner to look through... you posted a big wall of code. Provide data and it'll be easier to help you. – cory Mar 15 '16 at 18:26

2 Answers2

1

when you set scale_colour_grey() and then set scale_color_discrete(), your first color scale (grey) is eliminated and replaced with the new one (discrete). So I think what you want to do is remove scale_color_discrete() from your code, and add name = "Transplanted" inside your scale_colour_grey() line.

Matt74
  • 729
  • 4
  • 8
  • Thanks! We converged on the same solution. I have added 'scale_colour_manual(name="Transplanted", values = c("no" = "DarkGray","yes" = "Black")) +' to replace 'scale_color_discrete'. Now I just want to figure out how to add a black border around the symbols! – Keith W. Larson Mar 15 '16 at 16:49
0
# create plot
ggplot(data=trans_X,aes(x=Location, y=pred,group= Substrate)) + 
  geom_line(aes( linetype= Substrate,group=Substrate),size=1)+
  geom_point(data=trans_X, aes(shape=transferred, group= transferred,fill=transferred,color=transferred),size=6)+
  geom_errorbar(data=trans_X, position=position_dodge() ,aes(ymin=pred-2*sd,ymax=pred+2*sd, color=transferred),size=0.51,width=0.1)+
  my_theme + 
  scale_shape_manual(name="Transplanted", values=c(21,24))+
  scale_colour_manual(name="Transplanted", values = c("no" = "black","yes" = "black")) +
  scale_fill_manual(name="Transplanted", values = c("no" = "black","yes" = "gray60"))+
  scale_linetype_manual(name="Wrackbed substrate",
                        breaks=c("Steninge","M\366lle","K\344mpinge","K\u00E5seberga"),
                        values=c(1,5,3,6))+
  labs(y="Predicted mean development time",x="Fly origin")

enter image description here

Keith W. Larson
  • 1,543
  • 2
  • 19
  • 34