cowplot

Vertically align faceted ggplots of different heights when using coord_equal()

拥有回忆 提交于 2019-12-05 11:41:45
I am trying to combine two FACETED ggplot objects with coord_equal() using cowplot::plot_grid() or egg::ggarrange() and vertically align them. The egg::ggarrange() approach works fine for UNFACETED plots, with the solution posted here . However, the egg::ggarrange() solution breaks down when faceting is included. The plots are correctly aligned, but the units of the y-axes are twice as large as those of the x-axes . Any suggestions for how to generalize this for faceting? dat1 <- data.frame(x = rep(1:10, 2), y = 1:20, z = rep(c("A", "B"), 10)) dat2 <- data.frame(x = 1:10, y = 1:10, z = rep(c(

How to align an ordinary ggplot with a faceted one in cowplot?

妖精的绣舞 提交于 2019-12-03 18:40:44
问题 I'm trying to arrange plots in a publication-ready way with the use of cowplot package. I just want the panels to be equally sized and labeled. Reproducible expample library(ggplot2) library(cowplot) gg1 <- ggplot(mtcars)+ geom_point(aes(x=mpg,y=hp))+ theme_bw()+ theme(aspect.ratio=1) gg2 <- ggplot(mtcars)+ geom_point(aes(x=mpg,y=hp,fill=cyl))+ facet_wrap(~cyl,ncol=2)+ theme_bw()+ theme(aspect.ratio=1, legend.position='none') output <- plot_grid(gg1,gg2, labels = c('A','B'),label_size = 20)

How can I align multiple plots by their titles instead of plot area?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 07:19:58
问题 I'm using egg to align multiple plots on a page. I'm wondering if it's possible to align two columns by the titles a) and c) instead of plot area? Thanks! Code: library(egg) library(grid) p1 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + ggtitle("a)") p1 p2 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + facet_wrap(~ cyl, ncol = 2, scales = "free") + guides(colour = "none") + theme() + ggtitle("b)") p2 p3 <- ggplot(mtcars, aes(mpg, wt, colour =

How to align an ordinary ggplot with a faceted one in cowplot?

蓝咒 提交于 2019-11-30 00:17:36
I'm trying to arrange plots in a publication-ready way with the use of cowplot package. I just want the panels to be equally sized and labeled. Reproducible expample library(ggplot2) library(cowplot) gg1 <- ggplot(mtcars)+ geom_point(aes(x=mpg,y=hp))+ theme_bw()+ theme(aspect.ratio=1) gg2 <- ggplot(mtcars)+ geom_point(aes(x=mpg,y=hp,fill=cyl))+ facet_wrap(~cyl,ncol=2)+ theme_bw()+ theme(aspect.ratio=1, legend.position='none') output <- plot_grid(gg1,gg2, labels = c('A','B'),label_size = 20) print(output) The code produces this plot. As you may see, neither the horizontal axises match, nor do

for loop with ggplots produces graphs with identical values but different headings

情到浓时终转凉″ 提交于 2019-11-29 11:22:59
I have read lots of posts about using loops for ggplot to generate lots of graphs, but cannot find any that explain my problem... I have a dataframe and am trying to loop over 92 columns, creating a new graph for each column. I want to save each plot as a separate object. When I run my loop (code below) and print the graphs, all the graphs are correct. However, when I change the print() command with assign(), the graphs are not correct. The titles are changing as they should, however the graph-values are all identical (they are all the values for the final graph). I found this out because when

Marginal plots using axis_canvas in cowplot: How to insert gap between main panel and marginal plots

梦想与她 提交于 2019-11-28 09:43:52
问题 The following came up in a comment to this post: When making marginal plots with the axis_canvas() function in cowplot, how can we create a gap between the main plot and the marginal plot? Example code: require(cowplot) pmain <- ggplot(data = mpg, aes(x = cty, y = hwy, color = factor(cyl))) + geom_point() + xlab("City driving (miles/gallon)") + ylab("Highway driving (miles/gallon)") + theme_minimal() xbox <- axis_canvas(pmain, axis = "x", coord_flip = TRUE) + geom_boxplot(data = mpg, aes(y =

for loop with ggplots produces graphs with identical values but different headings

为君一笑 提交于 2019-11-28 04:43:26
问题 I have read lots of posts about using loops for ggplot to generate lots of graphs, but cannot find any that explain my problem... I have a dataframe and am trying to loop over 92 columns, creating a new graph for each column. I want to save each plot as a separate object. When I run my loop (code below) and print the graphs, all the graphs are correct. However, when I change the print() command with assign(), the graphs are not correct. The titles are changing as they should, however the

R assigning ggplot objects to list in loop

流过昼夜 提交于 2019-11-28 01:44:59
I'm using a for loop to assign ggplots to a list , which is then passed to plot_grid() (package cowplot ). plot_grid places multiple ggplots side by side in a single figure. This works fine manually, but when I use a for loop , the last plot generated is repeated in each subframe of the figure (shown below). In other words, all the subframes show the same ggplot. Here is a toy example: require(cowplot) dfrm <- data.frame(A=1:10, B=10:1) v <- c("A","B") dfmsize <- nrow(dfrm) myplots <- vector("list",2) count = 1 for(i in v){ myplots[[count]] <- ggplot(dfrm, aes(x=1:dfmsize, y=dfrm[,i])) + geom

R assigning ggplot objects to list in loop

懵懂的女人 提交于 2019-11-27 04:51:16
问题 I'm using a for loop to assign ggplots to a list , which is then passed to plot_grid() (package cowplot ). plot_grid places multiple ggplots side by side in a single figure. This works fine manually, but when I use a for loop , the last plot generated is repeated in each subframe of the figure (shown below). In other words, all the subframes show the same ggplot. Here is a toy example: require(cowplot) dfrm <- data.frame(A=1:10, B=10:1) v <- c("A","B") dfmsize <- nrow(dfrm) myplots <- vector(

Cowplot made ggplot2 theme disappear / How to see current ggplot2 theme, and restore the default?

耗尽温柔 提交于 2019-11-26 23:10:39
I recently installed the cowplot package. However, after doing this I noticed that my ggplots are missing their background and grid lines of theme_grey() ! The code to create each of the above plots is: result_df %>% ggplot(aes_string(x = 'p', y = 'r')) + # theme_grey() + # uncomment this line to produce plot on right geom_point(aes(group = c), size = 0.5) + geom_line(aes(group = c), size = 0.2, linetype = 'dotted') + theme(axis.text.x=element_text(angle = 90, hjust = 1, vjust = 0.5)) + facet_grid(b ~ e, scales = "free_y") + scale_x_continuous(breaks = seq(0, 10, 2)) Without explicitly calling