Questions tagged [cowplot]

The cowplot package is a simple add-on to ggplot2. It is meant to provide a theme for ggplot2 that is especially useful for formatting plots for publication in academic journals, and it also provides tools to neatly arrange multiple plots of different types, while minimizing the amount of required fiddling with sizes of axis labels, plot backgrounds, etc.

Cowplot

The cowplot package is a simple add-on to ggplot2. It is meant to provide a theme for ggplot2 that is especially useful for formatting plots for publication in academic journals, and it also provides tools to neatly arrange multiple plots of different types. while minimizing the amount of required fiddling with sizes of axis labels, plot backgrounds, etc.

Official CRAN Documentation

https://cran.r-project.org/web/packages/cowplot/index.html

CRAN Resources

284 questions
7
votes
2 answers

ggplot: Boxplot by several categorical variables

I am trying to plot several boxplots in one chart using ggplot2. I have 1 continuous variable and several factors. I would like to have a single Y axis and each pair of boxplots to have their own x axis with their own factor levels. So far, I tried…
user2053921
  • 73
  • 1
  • 4
7
votes
1 answer

Is it possible to avoid axis label overlapping by ggrepel?

I am drawing heatmap with ggplot2. Several ticks on y axis need to be labeled. However,some of them are too close and overlap. I know ggrepel could separate text labels, but currently I have not worked out for my problem. My code is as following.…
PengY
  • 73
  • 1
  • 4
7
votes
1 answer

Shared panel border with cowplot and plot_grid

I'm trying to draw a border around two plots that have been aligned with plot_grid from the cowplot package. Please see the following example (modified from the "Changing the axis positions" vignette): require(gtable) require(cowplot) # top plot p1…
tractorjack
  • 127
  • 8
6
votes
0 answers

R - cowplot: arrange png image and ggplot, using plot_grid

I am trying to arrange a png image and a ggplot object side by side using plot_grid from cowplot package: library(cowplot) library(tableHTML) sg <- data.frame(start = c(0,5,10), end = c(10,20,30), duration =…
Ant
  • 113
  • 10
6
votes
1 answer

Longer plot labels move to the right when arranging plots with plot_grid from cowplot

I was asked this question on Twitter and thought it might be good to have it here. When making labeled, side-by-side plots with plot_grid(), things work as expected for single-letter labels: library(cowplot) p1 <- ggplot(iris, aes(x = Sepal.Length,…
Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
5
votes
1 answer

Combine multiple gt tables to single one plot

With code below (edited basing on code from here) I generates two example tables with gt package: library(tidyverse) library(patchwork) library(gt) p1 <- mtcars %>% head(5) %>% gt() p2 <- mtcars %>% tail(5) %>% gt() # using wrap…
ah bon
  • 9,293
  • 12
  • 65
  • 148
5
votes
1 answer

Align facetted ggplots (facet_wrap) with cowplot in R

I am trying to align two panel plots, generated with a facet_wrap in ggplot in the following manner (note: panel A needs to stay empty): I noticed, however, that the y-axes of panel B are not exactly aligned with the y-axes from the last to plots…
user213544
  • 2,046
  • 3
  • 22
  • 52
5
votes
2 answers

Saving ggplot in EPS format for editing in Adobe Illustrator -- problem with text

Question I'd like to save a ggplot from R for editing in Adobe Illustrator (AI). I can save the plot in EPS or PS format with ggsave, but the plot always brings along some shading around the text. Is there a way to fix this in R or Adobe…
twb10
  • 533
  • 5
  • 18
5
votes
4 answers

ggplot2 - Correctly arrange odd number of plots into one figure

I have an odd number of plots to arrange into one figure and I desire to show the last plot centered in the last row of the figure. Here some sample data: library(ggplot2) set.seed(99) x_1 = data.frame(z = rnorm(100)) x_2 = data.frame(z =…
aaaaa
  • 149
  • 2
  • 18
  • 44
5
votes
1 answer

Multiple plots in for loop ignoring par

I am trying to generate 10 pairs of plots with a few pairs per page of plots, and am using a for loop to construct the pairs. However, the plots are sent to the device as separate plots instead of pages. The MWE below has identical constructions for…
JenB
  • 17,620
  • 2
  • 17
  • 45
5
votes
3 answers

ggplot: align multiple faceted plots - facets all different sizes

I am trying to align multiple plots with facets. My problem is somewhat minor but irratating: I can make a plot so that the plot areas are aligned and the facets themselves are aligned, but the facet strips are not all the same width. If the labels…
Reilstein
  • 1,193
  • 2
  • 11
  • 25
5
votes
2 answers

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

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…
Kevin
  • 491
  • 3
  • 10
5
votes
2 answers

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

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))) + …
Tung
  • 26,371
  • 7
  • 91
  • 115
5
votes
1 answer

Align shared legends to the center of the plot grid (with cowplot)

The reproducible example can be found in this tutorial for the package cowplot. https://cran.r-project.org/web/packages/cowplot/vignettes/shared_legends.html Copying example code: library(ggplot2) library(cowplot) #down-sampled diamonds data…
nouse
  • 3,315
  • 2
  • 29
  • 56
5
votes
1 answer

Keeping plot spacing intact using Cowplot align

I am trying to make some 'close stacked' plots using Cowplot. I can get the effect I want using the following MWE: library(ggplot2) library(cowplot) disp_plot <- ggplot(data=mtcars,aes(x= hp,y=disp)) + geom_point()+ theme(plot.margin…
JP Janet
  • 185
  • 6
1
2
3
18 19