I am trying to build multiple datasets on the same plot. For example, below, I have two sets of experiments with the settings: "P-0.1" and "P-0.2", which is indicated by coefficient B. For each experiment, I have three output values "P", "Q", "O" , as indicated by the multiplier A. I grouped the experiments by fill color and grouped the outputs by color, line type, and shape.
library(ggplot2) dat <- data.frame( A = factor(c("O", "O", "P", "P", "Q", "Q", "O", "O", "P", "P", "Q", "Q"), levels=c("O", "O", "P", "P", "Q", "Q","O", "O", "P", "P", "Q", "Q")), B = factor(c("P-0.1", "P-0.1", "P-0.1", "P-0.1","P-0.1", "P-0.1", "P-0.2", "P-0.2", "P-0.2", "P-0.2", "P-0.2", "P-0.2"), levels = c("P-0.1", "P-0.1", "P-0.1", "P-0.1","P-0.1", "P-0.1", "P-0.2", "P-0.2", "P-0.2", "P-0.2", "P-0.2", "P-0.2")), X = c( 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), Y = c(10, 15, 12, 13, 9, 14, 30, 20, 32, 21, 27, 19) ) p = ggplot(data=dat, aes(x=X, y=Y, colour=A, size=A, shape=A, linetype=A, fill=B, group=interaction(A,B))) + geom_point() + geom_line() + theme_bw() p = p + geom_point(size=4, alpha=0) + geom_point(size=4, show.legend=FALSE) + guides(shape = guide_legend(nrow=3, byrow = TRUE, keywidth = 1.5, keyheight = 1), colour = guide_legend(override.aes = list(alpha=1))) p = p + scale_shape_manual(name="", values=c(21,22,23)) p = p + scale_colour_manual(name="", values=c("#005ccc", "#007700", "#56B4E9")) p = p + scale_linetype_manual(name="", values=c(0,0,1)) p = p + scale_size_manual(name="", values = c(1, 1, 1)) p = p + scale_fill_manual(name="", values = c("red", "blue"))
The code above draws the picture correctly, but I get black circles in the legend for the fill bar, where I expected filled red and blue squares. How to fix it?
