Hi:
You did not provide a reproducible example, so the one offered below
is a guess at what your intended example contains. From appearances,
the length of the two vectors fed as values in the scale functions are
the same length as the data points, so one option is to put those
values into the data frame itself prior to plotting. In my example
below, the colors appear to be unique, so I did not assign a factor to
it, even though you appear to have done so in your examples. OTOH,
since the shape values were repeated, it made sense to define a
corresponding factor. This way I could illustrate both
scale_identity() and scale_manual() and let you decide which one you
prefer.
library(ggplot2)
# Reproducible example (mod the random seed)
DF <- data.frame(x = rnorm(12), y = rnorm(12),
shpfac = factor(1:3, levels = LETTERS[1:3]),
col = c("#006633", "#009900", "#00FF66",
"#CC9900", "#FFCC00","#FFFF66",
"#003399", "#0066CC", "#0099CC",
"#9900CC", "#CC00FF", "#FF00FF"),
shp = c(15, 16, 17, 15,16,17,15,16,17,15,16,17))
ggplot(DF, aes(x = x, y = y, color = col, shape = shpfac)) +
geom_point() +
scale_color_identity() +
scale_shape_manual(values = DF$shp)
By default, scale_identity() applies the aesthetic mapping in the plot
but does not create a legend guide. To include it, you need to add
guide = "legend" as an argument to the scale_color_identity call, but
the legend text values will be the hex codes. scale_identity()
directly maps the levels of the factor to the values of the
corresponding aesthetic.
Looking at your example again:
<snip>
> ggplot(graph_prox, aes(log_Ha_conv, PROX_MN))+
> geom_point( aes(colour=factor (Scenarios)),size = 4)+
> scale_color_manual(values=c("#006633", "#009900", "#00FF66",
> "#CC9900", "#FFCC00","#FFFF66",
> "#003399", "#0066CC", "#0099CC",
> "#9900CC", "#CC00FF", "#FF00FF"))+
> scale_shape_manual(values = c(15, 16, 17, 15,16,17,15,16,17,15,16,17))
you have PROX_MN defined in the initial aes(), but did not assign an
aesthetic to it. Since there is no explicit mention of what is to be
associated with the shape aesthetic, I'm not surprised that ggplot2
ignored the scale_shape_manual() code and failed to plot distinct
shapes. If your intention was to map PROX_MN to shape and _assuming it
is a factor with three levels_, try something like this:
ggplot(graph_prox, aes(log_Ha_conv, shape = PROX_MN)) +
geom_point( aes(colour=factor (Scenarios)),size = 4) +
scale_color_manual(values=c("#006633", "#009900", "#00FF66",
"#CC9900", "#FFCC00","#FFFF66",
"#003399", "#0066CC", "#0099CC",
"#9900CC", "#CC00FF", "#FF00FF")) +
scale_shape_manual(values = c(15, 16, 17))
If that doesn't work or the toy example above doesn't help, please
provide a reproducible example for the list to diagnose.
Dennis