0

Most of my plots are made with ggplot2 and the ggsave command saves them where they should be with one line. However, mosaic plots using the vcd package are best for my data. Problem: I don't get an error message with the following code. R says that it has saved my plot, but the plot that gets saved is the last ggplot plot I created, not the mosaic plot I want. Of course I can manually save in RStudio, but I'm quite sure there is a better way. Any ideas?

Onlyaround <- subset(prepData, preposition=="around")
attach(Onlyaround)
mytable <- table(exp_group, session, result)
ftable(mytable)
mosaic(mytable, shade=TRUE, legend=TRUE, main = "Around by Group")
margin.table(mytable)
ggsave("pics/around_mosaic.png")
detach(Onlyaround) 
sparkyjump
  • 97
  • 1
  • 9
  • Henrik, my question is essentially the same. Knowing what I know now, "How do I save something that is not ggplot?" would have been what I needed to know. The words "as image on the disk" were confusing to me so I didn't put 1 and 1 together. Thanks! – sparkyjump Jun 14 '17 at 13:22

1 Answers1

6

ggsave() is in fact the command to save ggplots, so it's no surprise that it doesn't save you mosaic plot. The standard 'R' way to save plots will work just fine:

jpeg("pics/around_mosaic.png")
mosaic(mytable, shade=TRUE, legend=TRUE, main = "Around by Group")
dev.off()
psychOle
  • 1,054
  • 9
  • 19