0

I am making a figure using the following codes:

d1 <- data.frame(time    = c(0,15,60,120),
                 number = c(0, 5, 5, 10, 0, 20, 20, 25),
                 arm     = c(rep("A",4), rep("B",4)))


ggplot(d1, aes(x = time, y = number, color = arm)) +
  scale_color_grey(start = 0.6, end = 0.2, guide = F) +
  geom_point(aes(shape = arm), 
             size = 3, 
             position = position_dodge(width=0)) +
  geom_line(aes(), 
            position = position_dodge(width=0)) +
  scale_x_continuous(name = "Time",breaks=c(0,15,60,120)) + 
  scale_shape_discrete(name = " ", 
                       labels = c("A type","B type")) +
  theme(axis.title.x=element_text(size=9),
        legend.position = "top",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) + 
  ylab("People")
  

enter image description here

HOWEVER, I noticed that the dot color of Type A is not grey, but black.
Is there anyway that I can manually change it accordingly?
If possible, I would like to keep the function "scale_color_grey".

Thanks!!

KLee
  • 105
  • 1
  • 9

1 Answers1

1

Just make sure you have both a scale and a color guide and make sure the names and labels match up. This should work

ggplot(d1, aes(x = time, y = number, color = arm)) +
  scale_color_grey(start = 0.6, end = 0.2, name = " ", labels = c("A type","B type")) + 
  scale_shape_discrete(name = " ", labels = c("A type","B type")) +
  ...

This will merge both legends into one. enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295