2
data = cbind(c("A","B","C","A"), c("John", "Kendra", "Martin", "Steve"), c("12","12","13","14"))
colnames(data) = c("Group", "Name", "Score")
data = as.data.frame(data)
p = ggplot(data, aes(x=Name, y=Score, fill=Name)) + geom_point(pch = 19, aes(col=Group)) + scale_colour_manual(values=c("black", "red", "green"))
print(p)

Hey, this code produces two legends: Name and Group. How do I get rid of the legend for Name? I mean the entire legend, not just its title. Edit: I have just figured it out myself. You do it by saying:

p = p + guides(fill=FALSE)
user132290
  • 179
  • 1
  • 2
  • 8

1 Answers1

5

I'll slightly adjust your example to something that works for me

You can use theme to modify the entire legend, but if you want to restrict your modification to individual elements, use guide instead:

data <- cbind(c("A","B","C","A"), c("John", "Kendra", "Martin", "Steve"), c("12","12","13","14"))
colnames(data) <- c("Group", "Name", "Score")
data <- as.data.frame(data)

p <- ggplot(data, aes(x = Name, y = Score, fill = Name)) + 
  geom_point(pch = 19, aes(col = Group)) + 
  scale_colour_manual(values = c("black", "red", "green")) +
  guides(fill = FALSE); p

Nicely explained in more detail here: cookbook for R.

Hope this helps :)

JanLauGe
  • 2,297
  • 2
  • 16
  • 40
  • What's the 'f3' bit by the way? – JanLauGe Mar 17 '17 at 16:51
  • Sorry, the f3 was just geom_point. Thanks, but you misunderstood my question. I want to remove the whole part of legend for the entries from column Name, not just its title. – user132290 Mar 17 '17 at 22:20
  • Oups, my bad, apologies! In this case you can use `guides` as well, but just set the entire element to `FALSE`. So instead of `guides(fill = guide_legend(title = NULL))` use `guides(fill = FALSE)` I've changed my answer accordingly. – JanLauGe Mar 18 '17 at 10:56