tags:

views:

94

answers:

2

Before presenting the actual data, I would like to make a plot identical to the one with data but then without the data points in there. This helps me in explaining how to interpret such a plot without distracting the audience with the actual data that will be in the plot.

So in the code below I would basically want to exchange the geom_point() with geom_blank(). No problem.

However, this also removes the color and size information from the legends that the plot code creates. Is there a way to get this back?

ggplot(vas, aes(x=time, y=pain, colour=light.color, size=light.intensity)) + 
  #geom_point(na.rm=FALSE) +
  geom_blank() + 
  facet_wrap(~ppno) +
  scale_colour_manual(values=cols) +
  scale_y_continuous(name="VAS Pain (a.u.)") +
  scale_x_continuous(name="Time (minutes)")

What is proper way to get the color indications back into the legend(s). Now they only display the value(s) of the various levels of a certain parameter (colour or size) but not the actual graphical element (a color or a size of a dot) that goes with a certain level.

A: 

Could you plot two geom_points() - one with the color of your background?

ggplot(cars, aes(x=speed, y=dist))+
geom_point(aes(col=speed))+
geom_point(colour="white")+
theme_bw()
Andreas
Thank you for your suggestion! I already thought of this idea but discarded it because I rather like the default gray-scale grid that ggplot() uses. So it is very difficult in that case to find the right color that fades into the background (also because each point has to have two colors, one for the background and when it intersects a grid line, also white).
Paul
That makes sense. you could always plot just the legend, and an empty plot. a bit like this: http://learnr.wordpress.com/2009/05/26/ggplot2-two-or-more-plots-sharing-the-same-legend/
Andreas
+1  A: 

How about hiding the actual points outside the plotting window? Something along these lines:

ggplot(cars, aes(x=speed+100, y=dist))+ #move x values to the right
  geom_point(aes(col=speed))+
  scale_x_continuous(at=seq(5,125,by=5), limits=c(0,30)) #set plotting window
Aniko