cowplot

ggplot - Multiple legends arrangement

早过忘川 提交于 2019-12-18 06:00:24
问题 I want to arrange mutiple legend in ggplot with multiple rows and columns. However currently, from the documentation I can only decide there direction or manipulate rows/columns within 1 legend. Am I overlook something? Thanks for any reference point to the solution. Here is the sample code and what I have done and the expect result. data <- seq(1000, 4000, by=1000) colorScales <- c("#c43b3b", "#80c43b", "#3bc4c4", "#7f3bc4") names(colorScales) <- data ggplot() + geom_point(aes(x=data, y=data

cowplot: axis title forcefully aligned when aligning two plots

自古美人都是妖i 提交于 2019-12-14 04:04:40
问题 This code replicates the problem: library(ggplot2) set.seed(0) df <- data.frame(ID = letters[1:10], Var = rnorm(10), "Some_very_long_label_names" = rnorm(10), "Not_so_long" = rnorm(10), "Short" = rnorm(10), "Incredibly_long_label_name_why_oh_why" = rnorm(10), "Etc" = rnorm(10)) melted_df <- reshape2::melt(df) p1 <- ggplot(df, aes(ID, Var)) + geom_bar(stat = "identity") + theme(axis.title.x = element_blank()) p2 <- ggplot(melted_df, aes(ID, variable)) + geom_tile(aes(fill = value)) + guides

How to put plots without any space using plot_grid?

无人久伴 提交于 2019-12-12 11:06:26
问题 I'm doing an arrangement of 2x2 plots. The plots share the same axis, so I want to put them together, e.g. This code: library(ggplot2) library(cowplot) Value <- seq(0,1000, by = 1000/10) Index <- 0:10 DF <- data.frame(Index, Value) plot <- ggplot(DF, aes(x = Index, y = Value)) + geom_line(linetype = 2) + theme(aspect.ratio = 0.5) plot_grid(plot, plot, plot, plot, align = "hv", ncol = 2) produces But I'd like something like: How can I achieve a similar result? 回答1: I think this is a case for

How do I customize the margin and label settings with plot_grid?

↘锁芯ラ 提交于 2019-12-11 12:54:02
问题 I would like to have the title not be chopped off and have the axis labels removed from this chart that I generated with plot_grid from cowplot. Here is my code data(mtcars) library(ggplot2) library(cowplot) mpg = ggplot() + geom_boxplot(aes(y = mpg,x = as.factor(cyl)),data=mtcars) + coord_flip() am=ggplot() + geom_boxplot(aes(y = mpg,x = as.factor(am)),data=mtcars) + coord_flip() vs=ggplot() + geom_boxplot(aes(y = mpg,x = as.factor(vs)),data=mtcars) + coord_flip() gear = ggplot() + geom

R, why is cowplot plot_grid() generating tiny pictures side by side?

半腔热情 提交于 2019-12-11 05:02:09
问题 I'm trying to put some plots side by side using the cowplot package in R. Here's the (quite bad) result I am getting: As you can see, this image is full of troubles: the plots are tiny and too small, the text font sizes are too big, and there's too much blank space left. I am able to generate and save correctly each of the three plots, but I get that disaster image when I run this command: general_plot <- plot_grid(plot_cf, plot_pos_neg, plot_scores, ncol = 2, align="h", labels=c("A", "B", "C

Draw border around certain rows using cowplot and ggplot2

北城以北 提交于 2019-12-10 13:18:29
问题 I want to somehow indicate that certain rows in a multipanel figure should be compared together. For example, I want to make this plot: Look like this plot (with boxes around panels made with PowerPoint): Here's the code I made to use the first plot. I used ggplot and cowplot: require(cowplot) theme_set(theme_cowplot(font_size=12)) # reduce default font size plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + geom_point(size=2.5) plot.diamonds <- ggplot(diamonds, aes

cowplot: How to customize the gaps between main panel & marginal plots by modifying axis limits?

时光怂恿深爱的人放手 提交于 2019-12-10 10:21:28
问题 This is a followup question on one of the solutions provided by @ClausWilke (see post) to insert gap between main panel & marginal plots. How does one decide the (scale_x_continuous) limits? Also, what’ll happen if we used “NA” as the upper limit? # Example with limits set to: (-2,4.5) require(ggplot2) require(cowplot) pmain <- ggplot(data = mpg, aes(x = cty, y = hwy)) + geom_point() + xlab("City driving (miles/gallon)") + ylab("Highway driving (miles/gallon)") + theme_grey() xbox2 <- axis

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

老子叫甜甜 提交于 2019-12-07 05:02:26
问题 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

Add a common legend

筅森魡賤 提交于 2019-12-06 12:32:13
I was trying to do a multiplot with ggplot2 . This was my initial code nucmer_s1 <- ggarrange(eight_uniform, ten_uniform, twelve_uniform, fourteen_uniform, sixteen_uniform, ncol=3, nrow=2, common.legend = TRUE, legend="bottom") getting this error Error in plot$scales : $ operator is invalid for atomic vectors then. annotate_figure(nucmer_s1, top = text_grob("Genomas validados con distribución de datos equilibrada", color = "black", face = "bold", size = 12)) however I obtain the graphic But I need to put a title in the each plot a title so I changed to this one nucmer_s1 <-grid.arrange( eight

cowplot: How to customize the gaps between main panel & marginal plots by modifying axis limits?

谁说胖子不能爱 提交于 2019-12-06 02:57:38
This is a followup question on one of the solutions provided by @ClausWilke ( see post ) to insert gap between main panel & marginal plots. How does one decide the (scale_x_continuous) limits? Also, what’ll happen if we used “NA” as the upper limit? # Example with limits set to: (-2,4.5) require(ggplot2) require(cowplot) pmain <- ggplot(data = mpg, aes(x = cty, y = hwy)) + geom_point() + xlab("City driving (miles/gallon)") + ylab("Highway driving (miles/gallon)") + theme_grey() xbox2 <- axis_canvas(pmain, axis = "x", coord_flip = TRUE) + geom_boxplot(data = mpg, aes(y = cty, x = 1)) + scale_x