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)?

2
  • Take a look at facet_grid(). Commented Nov 19, 2013 at 14:48
  • Yesterday I answered a similar question 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. Commented Nov 19, 2013 at 14:49

1 Answer 1

1

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

+ facet_grid(.~Actor)

To the ggplot call.

Sign up to request clarification or add additional context in comments.

1 Comment

No. I do not want one plot with 10 facets, but 10 plots.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.