Dear Ryan,
You cannot merge the legend if you are using continuous and discrete variables.
I think you need create discrete values (if you want to use shape) and account for the combination of two variables, if you want to have only one legend in the plot…….
mydata.n$group <- interaction(mydata.n$shape,mydata.n$colour)
a <- ggplot(data=mydata.n, aes(x = x, y = y, shape=group, colour=group))
a + geom_point()
--Kaori
From: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com]
On Behalf Of RyanR
Sent: Thursday, April 04, 2013 1:34 PM
To: ggp...@googlegroups.com
Subject: Combining legend colour and shape using values from data frame
Hello all,
I am having some trouble getting a plot legend together.
In my dataframe I have added a column with the shape and colour I would like to use for plotting. When I use these values I am unable to figure out how to combine them in my legend. I have two examples of what I want to do.
1) This is a simple plot where I just use the colour and shape for the symbols.
2) This is slightly more complicated as I add in scaling from a third variable.
What I would like to do is combine the colour and shape into the legend for a single entry.
Here is what I use:
#START
library(ggplot2)
mydata = read.csv("example.csv") # file available at https://www.dropbox.com/s/lw5ophv98vdizpu/example.csv
mydata.n<-mydata
mydata.n[,c(4:6)]<-sapply(mydata.n[,c(4:6)],as.numeric)
#Plot 1
a <- ggplot(data=mydata.n, aes(x = x, y = y, shape=shape, colour=colour))
a + geom_point() + scale_shape_identity(guide="legend") + scale_colour_identity(guide="legend")
#Plot 2
b <- ggplot(data=mydata.n, aes(x = x, y = y, shape=shape, colour=colour, size=z))
b + geom_point() + scale_shape_identity(guide="legend") + scale_colour_identity(guide="legend")
#STOP
Thanks for any help,
-Ryan
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.