0

I want to plot 10 figures, with the same variable(s), but different actors (I want to have a plot for every actor).

actor1 <- subset (actor, actor$Actor=="Actor1")

plot_actor1 <- ggplot(actor1, aes(x = Date, y = Var))+
  geom_point(shape=15)
  ylim(0,30)+
  geom_hline(yintercept=12)+
  geom_hline(yintercept=17)+
  theme_bw()

pdf("actor1", paper='A4r', width=11)
actor1
dev.off()

Data ("actor" - excerpt):

Actor   Date    Var
Actor1  0101    12
Actor1  0102    14
Actor1  0103    17
Actor1  0104    11
Actor1  0105    9
Actor1  0106    21
Actor2  0101    6
Actor2  0102    17
Actor2  0103    15
Actor2  0104    19
Actor2  0105    25
Actor2  0106    3

I could do that manually, but isn't there another solution (with a loop or a function), where I can replace the "actor1" with names of all my actors (from actor1 until actor10)?

Panu Haaramo
  • 2,932
  • 19
  • 41
feder80
  • 1,195
  • 3
  • 13
  • 34
  • Take a look at `facet_grid()`. – VLC Nov 19 '13 at 14:48
  • Yesterday I answered [a similar question](http://stackoverflow.com/questions/20048287/ddply-and-ggplot-generating-no-plot/20048855#20048855) about creating and saving several plots, looping over a grouping variable. You may check if you can adapt the answer to your specific needs. I know there are several other nice examples on SO. Cheers. – Henrik Nov 19 '13 at 14:49

1 Answers1

1

If I understand you correctly, you should be good just adding

+ facet_grid(.~Actor)

To the ggplot call.

colcarroll
  • 3,632
  • 17
  • 25