1

I have the following plot, plotting data coming from two different data-frames:

ggplot() + 
  stat_summary( data = d0_400, aes(x=number, y=(1-value), shape=as.factor(0), size=1 ) , fun.y=mean, geom="line" ) +
  stat_summary( data = d0_400, aes(x=number, y=(1-value), shape=as.factor(0), size=4 ) , fun.y=mean, geom="point" ) +
  stat_summary( data = d1_400, aes(x=number, y=(1-value), shape=as.factor(1), size=1 ) , fun.y=mean, geom="line" ) +
  stat_summary( data = d1_400, aes(x=number, y=(1-value), shape=as.factor(1), size=4 ) , fun.y=mean, geom="point" ) +
  scale_size(range = c(1,5), guide=FALSE) + 
  scale_shape_manual(values=c(0,1) )

With this code I get the following plot:

enter image description here

I would like to get the following instead:

  • A custom hexadecimal colour for the lines and the shapes
  • Optional: Shapes appearing bigger in the shape legend, as they are too hard to distinguish in this size, and filling them with white colour.
cross
  • 1,018
  • 13
  • 32

1 Answers1

1

For the coloured lines, just add a colour argument

p = ggplot() + 
  stat_summary( data = d0_400, ..., geom="line", colour = "#hexnum" )

Also, a quick google of the optional question took me to here:

The solution provided is

p = p + guides(shape=guide_legend(override.aes=list(size=5)))
Community
  • 1
  • 1
Akhil Nair
  • 3,144
  • 1
  • 17
  • 32
  • perfect! one more follow up, is it possible to fill the shapes with a certain colour. I tried `fill="#456987"` but did not work? – cross Jun 05 '15 at 10:52
  • Bit of a hack, but you could just change the point character. Add the argument `pch = 16` which should be a filled circle. Then the `colour` will effect it. – Akhil Nair Jun 05 '15 at 10:55
  • which function should I pass `pch` as a parameter? – cross Jun 05 '15 at 10:56
  • The `stat_summary` function. `stat_summary( data = d0_400, ..., geom="point", colour = "#AFE1EE", pch = 16 )`. If this isn't sufficient you'll get a more comprehensive answer if you ask a new question – Akhil Nair Jun 05 '15 at 10:58
  • what a hack! will need to find a way to override the shape in the legend. the `pch` does not reflect to the shape legend: `scale_shape_manual(values=c(0,1)` – cross Jun 05 '15 at 11:05