teri
teri

Reputation: 53

R ggplot2 scale_shape_manual not working but scale_colour_manual works

I would like to set the color and the shape of my 2 indicators which has been plotted in in two layes. The scale_color_manual works however the scale_shape_manual is not working. By having or not having this line "scale_shape_manual"; the result is the same and shape "16" (filled circle) is picked up?

comp_graph_1 <- ggplot() + 
  layer( mapping = aes(x=log(FV), y= msd, colour = "Reference"),   #factor(Dataset) 
  data = ref,
  stat = "identity",
  geom = "point",
  position = "identity")+ 
  layer(mapping = aes(x=log(FV), y= msd,  colour = "Target"),  #  "red" "blue"
        data = target,  #data = target[Is_Phone == 0],  
        stat = "identity",
        geom = "point",
        position = "identity")+ 
  theme(panel.background = element_rect(fill = 'white'), 
        panel.grid = element_line(colour = "grey90") , panel.ontop = FALSE)+ 
  theme(legend.justification = c(0, 0), legend.position = "bottom", 
        legend.background = element_rect(), legend.title = element_blank(), legend.key = element_rect(fill = "white"),
        legend.text = element_text(size = 9,colour = "#7F7F7F"), panel.border = element_blank(), 
        axis.line = element_line(color = "#7F7F7F"))+
  theme(plot.title = element_text(size = 16, colour = "#7F7F7F"), 
        axis.title.x = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F"), 
        axis.title.y = element_text(size = 11, hjust = 1, face = "bold", colour = "#7F7F7F")) +
  ggtitle(paste0(x, " / ", y, " distribution  ")) + xlab(paste0("log ", x)) + ylab(y) +
  scale_color_manual(values = c("Reference" ="#FFC000","Target"  = "#00AEEF")) +
  scale_shape_manual(values = c("Reference" =17, "Target"  = 4)) 

Upvotes: 1

Views: 3800

Answers (1)

Bill Perry
Bill Perry

Reputation: 492

I think where you have colour = "Target" you need a shape statement as well shape = "Target" and shape = "Reference" and it should work.

Upvotes: 1

Related Questions