0

I want to generate a multiple-column legend (2 or more) for the following figure using this piece of code. But the guides() does not work properly. Can someone help me?

library(ggplot2)
 testdf <- data.frame(site=unlist(strsplit(rawToChar(as.raw(65:90)),split = '')),
                              x = c(seq(0:24),80), y = seq(1:26))
 testdf$colours <- 'red'
 p <- ggplot(data=testdf,aes(x,y))
 p + scale_shape_manual(values=testdf$x)+
   scale_colour_manual(values=testdf$colours)+
   geom_point(aes(shape=site,colour=site),size=5)+
   guides(col=guide_legend(ncol=3,byrow=TRUE))

enter image description here

Thanks, Katie

2
  • 3
    guides(shape=guide_legend(ncol=3,byrow=TRUE)) will do, I think Commented Oct 7, 2015 at 13:41
  • Yes, it works! Thanks. Commented Oct 7, 2015 at 13:51

1 Answer 1

2
col3 <- guide_legend(ncol = 3)
ggplot(testdf, aes(x = x, y = y, shape = site, colour = site)) + 
  geom_point() + 
  scale_shape_manual(values = testdf$x, guide = col3) + 
  scale_colour_manual(values = testdf$colours, guide = col3)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.