UBC-MDS / DSCI_522_Group304

DSCI 522 Group 304 Project - Are There Differences in FSA Scores Between Subgroups?
MIT License
0 stars 5 forks source link

Adding Figure Captions to Plots #100

Closed annychih closed 4 years ago

annychih commented 4 years ago

I didn't like the idea of saving each pair of charts to individual png files because each of our scripts actually generate 3 sets of charts (Reading, Writing, Numeracy) and I didn't want those Writing charts to be completely useless (in case we wanted to do something to them later), so I was fiddling with RStudio trying a few different ways to try and add a single figure caption for code chunks that included 2 charts. These are some of the things that technically worked but didn't produce anything nice (the graphs were generally too small). I'm putting them here for reference:

library(grid)

library(png)

library(gridExtra)

This makes them too small:

fig1a <- rasterGrob(as.raster(readPNG("../img/bar_plot_numeracy.png")))

fig1b <- rasterGrob(as.raster(readPNG("../img/bar_plot_reading.png")))

grid.arrange(arrangeGrob(fig1a, fig1b, nrow = 1, ncol = 2, widths = c(2,2)))

This didn't work:

library(ggplot2)

multiplot(fig1a, fig1b, cols =2)

This wasn't any better:

library(cowplot)

plot_grid(fig1a, fig1b, ncol = 2)

doesn't work:

fib1a <- readPNG("../img/bar_plot_numeracy.png")

fig1b <- readPNG("../img/bar_plot_reading.png")

grid.raster(fig1a, fig1b)

This was just as bad:

library(cowplot)

library(ggplot2)

p1 <- ggdraw() + draw_image('../img/bar_plot_numeracy.png', scale = 2)

p2 <- ggdraw() + draw_image('../img/bar_plot_reading.png', scale = 2)

plot_grid(p1, p2)

putting this outside in the regular markdown area didn't work either

test{width=100px} #test2{width=100px}

annychih commented 4 years ago

I ended up changing each of the scripts to output one png file for both boxplots.