Вот моя проблема:
Я делаю:
plot_grid(first_graph_by_mistake)
plot_grid(second_graph_on_purpuse)
ggsave("graph1.png")
против ТОЛЬКО
plot_grid(second_graph_on_purpose)
ggsave("graph2.png")
оба графика выглядят одинаково, но когда я делаю:
system("diff graph1.png graph2.png") it shows a difference.
Возможно, устройство png не сброшено и некоторые настройки отличаются, и поэтому diff показывает разницу.Как я могу сделать 2 графика точно такими же?Это мой ГЛАВНЫЙ запрос.
Я сделал это в очень длинном куске кода.Когда я пытаюсь сделать прекрасный пример, разница не показывает никакой разницы между двумя графиками.Я не в состоянии воспроизвести то, на что я ссылаюсь в своем запросе.
Здесь представлены:
library(cowplot)
library(grid)
plot.mpg.1 <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + geom_point(size=2.5)
plot.mpg.2 <- ggplot(mpg, aes(x = cty, y = displ, colour = factor(cyl))) + geom_point(size = 2.5)
plot.mpg.3 <- ggplot(mpg, aes(x = hwy, y = displ, colour = factor(cyl))) + geom_point(size = 2.5)
plot.mpg.4 <- ggplot(mpg, aes(x = drv, y = displ, colour = factor(cyl))) + geom_point(size = 2.5)
mygraphs <- list(plot.mpg.1,plot.mpg.2,plot.mpg.3,plot.mpg.4)
dummygraph <- mygraphs[[1]]
legend = get_legend(dummygraph + theme(legend.position = "bottom",legend.justification="center") + guides(fill = guide_legend(nrow = 1 )))
toplotlist <- lapply(mygraphs,function(x){x + theme(plot.margin = unit(c(0, 0, 0,0), "in"),legend.position="none")})
pmatrix <- do.call("plot_grid",toplotlist)
p<-plot_grid(pmatrix,legend,nrow=2,rel_heights = c(8,.2),rel_widths = c(10,1))
# Note : Please run first, the first section. Then run the second section.
######################################################################################################
# Without this line
# plot_grid(pmatrix,legend,nrow=2,rel_heights = c(64,1))
title <- ggdraw() + draw_label("My title", fontface='bold',size = 20)
semifinal <- plot_grid(title, p, ncol=1, rel_heights=c(0.1, 1))
blank <- grid.rect(gp=gpar(col="white"))
plot_grid(semifinal,blank,ncol=1,rel_heights=c(15,1))
ggsave(paste0("without_line.png"),height = 10,width = 10,dpi = 600)
########################################################################### ############################
# With this line
plot_grid(pmatrix,legend,nrow=2,rel_heights = c(64,1))
title <- ggdraw() + draw_label("My title", fontface='bold',size = 20)
semifinal <- plot_grid(title, p, ncol=1, rel_heights=c(0.1, 1))
blank <- grid.rect(gp=gpar(col="white"))
plot_grid(semifinal,blank,ncol=1,rel_heights=c(15,1))
ggsave(paste0("with_line.png"),height = 10,width = 10,dpi = 600)
###################################################################################################
# Now do
system("diff without_line.png with_line.png")