Closed ghost closed 3 years ago
I have the same issue. Even when the individual plots have legend.position = "bottom"
, the legend shows up on the side.
My current workaround is to export as SVG and modify it on Inkscape.
in v>=0.1.0.991 (current github version),
pg =p2 %>% insert_left(g) %>% insert_right(p1, width=.5)
print(pg) & theme(legend.position='bottom')
Is that possible to keep legend setting for an individual subplot?
options("aplot_guides" = "keep")
p1 <- p1 + theme(legend.position="top")
p2 %>% insert_left(g) %>% insert_right(p1, width=.5)
Tried to update aplot to use the new function but got an error as shown below:
* preparing ‘aplot’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘aplot_0.1.0.994.tar.gz’
* installing *source* package ‘aplot’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error: object ‘ggbreak2ggplot’ is not exported by 'namespace:ggfun'
Execution halted
need to install yulab-smu/ggfun
first.
It works. But it looks like the legend function still doesn't work as shown below:
library(ggplot2)
library(aplot)
options("aplot_guides" = "kepp")
a <- data.frame(x=rnorm(100),y=rnorm(100),type=rep(c("a","b"),each=50))
p <- ggplot(a,aes(x=x,y=y,fill=type)) + geom_point() + theme(legend.position = "none")
p_top <- ggplot(a,aes(x=x,fill=type)) + geom_density(alpha=0.5) +
theme(legend.position = c(0.9,0.9))
p_right <- ggplot(a,aes(y=y,fill=type)) + geom_density(alpha=0.5) +
theme(legend.position = "none")
ap <- p %>%
insert_top(p_top, height=.3) %>%
insert_right(p_right, width=.3)
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] aplot_0.1.0.994 cowplot_1.1.1 ggpubr_0.4.0 forcats_0.5.1
[5] stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_2.0.1
[9] tidyr_1.1.3 tibble_3.1.4 ggplot2_3.3.5 tidyverse_1.3.1
[13] ComplexHeatmap_2.8.0
options("aplot_guides" = "kepp")
should be:
options("aplot_guides" = "keep")
I already tried this:
options("aplot_guides" = "keep")
library(ggplot2)
library(aplot)
a <- data.frame(x=rnorm(100),y=rnorm(100),type=rep(c("a","b"),each=50))
p <- ggplot(a,aes(x=x,y=y,fill=type)) + geom_point() + theme(legend.position = "none")
p_top <- ggplot(a,aes(x=x,fill=type)) + geom_density(alpha=0.5) +
theme(legend.position = c(0.9,0.9))
p_right <- ggplot(a,aes(y=y,fill=type)) + geom_density(alpha=0.5) +
theme(legend.position = "none")
ap <- p %>%
insert_top(p_top, height=.3) %>%
insert_right(p_right, width=.3)
It's the same:
@GuangchuangYu , any suggestion on how to keep the legend not changed for each subplot?
The latest version works very nice.
Hi,
I am trying to adjust legend position in one of your example. For p2 graph (heatmap like graph). I am interested in to have legend at the bottom of this graph but instead legend for p2 is always coming to the right of the last inserted graph. Is it possible to change guides position after joining graphs ("What I need" on attached picture)?
Thanks, Dawid