fbreitwieser
4/27/2018 - 2:45 PM

common legend with cowplot

common legend with cowplot


a = read.delim("~/Accuracy_as_a_function_of_sketch_size_and_set_size.txt")
head(a)
a$rel_error = sqrt(a$Mean.squared.error) / a$Exact.size

a$p = factor(a$Sketch.size..log2.)
library(cowplot)
library(ggplot2)

plot1 = ggplot(a, aes(x=Exact.size, sqrt(Mean.squared.error) / Exact.size, 
                           col=p)) + scale_y_continuous(labels = scales::percent) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  geom_line() + geom_point() + cowplot::background_grid('y') + ggtitle("Mean sq error")

plot2 = ggplot(a, aes(x=Exact.size, Mean.bias / Exact.size, 
              col=p)) + scale_y_continuous(labels = scales::percent) +
  scale_x_log10(
    breaks = scales::trans_breaks("log10", function(x) 10^x),
    labels = scales::trans_format("log10", scales::math_format(10^.x))
  ) +
  geom_line() + geom_point() + cowplot::background_grid('y') + ggtitle("Mean bias")

main = cowplot::plot_grid(plot1 + theme(legend.position = "none"), plot2 + theme(legend.position = "none"))

cowplot::plot_grid(main, cowplot::get_legend(plot1), ncol=2, rel_widths = c(1, .1))