set.seed(1)df <- data.frame(x=c(rep("a", 10), rep("b", 10)), y=c(sample(1:4, 10, replace=T), sample(1:6, 10, replace=T)))
ggplot(data=df, aes(x=x, y=y)) + stat_sum(aes(group=x, color=y)) + scale_size_area(max_size=15) + scale_color_gradient(low="red", high="green")
You can normalize the y
values within the x
groups and use these to assign colors. The numbers in the legend become meaningless, though, and you’ll want to modify or get rid of it:
require(ggplot2)
require(plyr)
set.seed(1)
df <- data.frame(x=c(rep("a", 10), rep("b", 10)),
y=c(sample(1:4, 10, replace=T), sample(1:6, 10, replace=T)))
df <- ddply(df, .(x), transform, y2=(y-min(y))/(max(y)-min(y))) # <--- Normalized y values are "y2"
ggplot(data=df, aes(x=x, y=y)) +
stat_sum(aes(group=x, color=y2)) + # <--- Assign color to "y2"
scale_size_area(max_size=15) +
scale_color_gradient(low="red", high="green", breaks=c(0,1), # <--- Modify the scale labels
label=c("min.group", "max.group"))
You get:
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.