Getting legendary coloring in empty ggplot

Before presenting the actual data, I would like to make a graph identical to the graph with the data, but then without the data points. This helps me explain 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 like to exchange geom_point()for geom_blank(). No problems.

However, it also removes color and size information from the legends that the chart code creates. Is there any 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)")

How to return the color display to legend(s)? Now they display only the values โ€‹โ€‹of different levels of a certain parameter (color or size), but not the actual graphic element (color or size of a point) that corresponds to a certain level.

+6
4

? - :

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
+2

:

ggplot(vas, aes(x=time, y=pain, colour=light.color, size=light.intensity)) 
 + geom_point(size=0)
+1

Could you build two geo-ohmic points () - one with the background color?

ggplot(cars, aes(x=speed, y=dist))+
geom_point(aes(col=speed))+
geom_point(colour="white")+
theme_bw()
0
source

In the end, taking Aniko's offer (which I initially could not get to work, therefore was rejected, unrighteously). I came up with the following code.

vas2 <- vas
vas2$time <- vas2$time+181
pp <- p %+% vas2 #p is the above plot assigned to a variable.
pp + scale_x_continuous(name="Time (minutes)", limits=c(0,180)) 

So, it was just the shift of your data along the axis and the exception of this part

0
source

All Articles