Dear John Kane
Dear R community
Here my working example
1. Example that is working with legend=?top?. However, as mentioned, the legend
is in the middle of the top axis.
mylist<-list(p1, p2)
dev.new(width=28, height=18)
fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="top", labels = c("(A)", "(B)"), font.label
= list(size = 18, color = "black"), ncol=2)
fig1
2. My question is how I can position the legend on the topright of the top axis.
However, ?topright? is not a common label for legend in ggarrange (but in other
plot functions), so legend =?topright? is not working.
mylist<-list(p1, p2)
dev.new(width=28, height=18)
fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="topright", labels = c("(A)", "(B)"),
font.label = list(size = 18, color = "black"), ncol=2)
fig1
Kind regards
Sibylle
From: John Kane <jrkrideau at gmail.com>
Sent: Monday, February 5, 2024 1:59 PM
To: sibylle.stoeckli at gmx.ch
Cc: r-help at r-project.org
Subject: Re: [R] ggarrange & legend
Could you supply us with a MWE (minimal working example)of what you have so far?
Thanks.
On Mon, 5 Feb 2024 at 05:00, SIBYLLE ST?CKLI via R-help <r-help at
r-project.org <mailto:r-help at r-project.org> > wrote:
Dear R community
It is possible to adjust the legend in combined ggplots using ggarrange with
be positions top, bottom, left and right.
My question: Is there a function to change the position of the legend to
topright or bottomleft? Right and top etc are in the middle of the axis.
Kind regards
Sibylle
______________________________________________
R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
John Kane
Kingston ON Canada
[[alternative HTML version deleted]]
I'm sorry but that is not a working example.
A working example needs to create the plots being used.
For example, stealing some code from
https://rpkgs.datanovia.com/ggpubr/reference/ggarrange.html
#================================================================
data <https://rdrr.io/r/utils/data.html>("ToothGrowth")df <-
ToothGrowthdf$dose <- as.factor
<https://rdrr.io/r/base/factor.html>(df$dose)# Box plotbxp <-
ggboxplot
<https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html>(df,
x = "dose", y = "len", color = "dose", palette
= "jco")# Density
plotdens <- ggdensity
<https://rpkgs.datanovia.com/ggpubr/reference/ggdensity.html>(df, x
"len", fill = "dose", palette = "jco")
mylist<-list(bxp, dens)
dev.new(width=28, height=18)
fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="top",
labels = c("(A)", "(B)"), font.label = list(size = 18, color
"black"), ncol=2)
fig1
#====================================================================================
On Mon, 5 Feb 2024 at 08:44, <sibylle.stoeckli at gmx.ch> wrote:
> Dear John Kane
>
> Dear R community
>
>
>
> Here my working example
>
> 1. Example that is working with legend=?top?. However, as mentioned,
> the legend is in the middle of the top axis.
>
> mylist<-list(p1, p2)
>
> dev.new(width=28, height=18)
>
> fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="top",
> labels = c("(A)", "(B)"), font.label = list(size = 18,
color = "black"),
> ncol=2)
>
> fig1
>
>
>
> 1. My question is how I can position the legend on the topright of the
> top axis. However, ?topright? is not a common label for legend in
ggarrange
> (but in other plot functions), so legend =?topright? is not working.
>
> mylist<-list(p1, p2)
>
> dev.new(width=28, height=18)
>
> fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="topright",
> labels = c("(A)", "(B)"), font.label = list(size = 18,
color = "black"),
> ncol=2)
>
> fig1
>
>
>
> Kind regards
>
> Sibylle
>
>
>
> *From:* John Kane <jrkrideau at gmail.com>
> *Sent:* Monday, February 5, 2024 1:59 PM
> *To:* sibylle.stoeckli at gmx.ch
> *Cc:* r-help at r-project.org
> *Subject:* Re: [R] ggarrange & legend
>
>
>
> Could you supply us with a MWE (minimal working example)of what you have
> so far?
>
> Thanks.
>
>
>
> On Mon, 5 Feb 2024 at 05:00, SIBYLLE ST?CKLI via R-help <
> r-help at r-project.org> wrote:
>
> Dear R community
>
> It is possible to adjust the legend in combined ggplots using ggarrange
> with
> be positions top, bottom, left and right.
> My question: Is there a function to change the position of the legend to
> topright or bottomleft? Right and top etc are in the middle of the axis.
>
> Kind regards
> Sibylle
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
>
> John Kane
> Kingston ON Canada
>
--
John Kane
Kingston ON Canada
[[alternative HTML version deleted]]
Would something like this help?
library(ggplot2)
# Create a plot
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
labs(title = "Scatter Plot", x = "Weight", y = "Miles
Per Gallon")
# Add text at a specific location
p + annotate("text", x = min(mtcars$wt) + 23, y = max(mtcars$mpg) -
10, label = "Custom Text")
Tim
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of SIBYLLE
ST?CKLI via R-help
Sent: Monday, February 5, 2024 8:43 AM
To: 'John Kane' <jrkrideau at gmail.com>
Cc: r-help at r-project.org
Subject: Re: [R] ggarrange & legend
[External Email]
Dear John Kane
Dear R community
Here my working example
1. Example that is working with legend="top". However, as
mentioned, the legend is in the middle of the top axis.
mylist<-list(p1, p2)
dev.new(width=28, height=18)
fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="top", labels = c("(A)", "(B)"), font.label
= list(size = 18, color = "black"), ncol=2)
fig1
2. My question is how I can position the legend on the topright of the top
axis. However, "topright" is not a common label for legend in
ggarrange (but in other plot functions), so legend ="topright" is not
working.
mylist<-list(p1, p2)
dev.new(width=28, height=18)
fig1<- ggarrange(plotlist=mylist, common.legend = TRUE,
legend="topright", labels = c("(A)", "(B)"),
font.label = list(size = 18, color = "black"), ncol=2)
fig1
Kind regards
Sibylle
From: John Kane <jrkrideau at gmail.com>
Sent: Monday, February 5, 2024 1:59 PM
To: sibylle.stoeckli at gmx.ch
Cc: r-help at r-project.org
Subject: Re: [R] ggarrange & legend
Could you supply us with a MWE (minimal working example)of what you have so far?
Thanks.
On Mon, 5 Feb 2024 at 05:00, SIBYLLE ST?CKLI via R-help <r-help at
r-project.org <mailto:r-help at r-project.org> > wrote:
Dear R community
It is possible to adjust the legend in combined ggplots using ggarrange with be
positions top, bottom, left and right.
My question: Is there a function to change the position of the legend to
topright or bottomleft? Right and top etc are in the middle of the axis.
Kind regards
Sibylle
______________________________________________
R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
John Kane
Kingston ON Canada
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.