Open petzi53 opened 2 years ago
Thanks for reporting this. Have you tried this on older versions of ggplot2?
No, I haven't tried it with older versions of ggplot2. Maybe it is a regression? As you can see in an SO post, it worked several years ago. @alexandra-wall reported a similar issue last year.
The relevant code looks correct to me https://github.com/sinhrks/ggfortify/blob/912ba6d39feb1537b30997632b1d125500c1058d/R/fortify_stats_density.R#L48-L51
Could you try the following?
ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1, xlab="x axis", ylab="y axis")
It reports an error:
Error in func(x, ...) :
unused arguments (xlab = "x axis", ylab = "y axis")
Just to say, I'm having the same issue and get the same error as petzi53
Okay I fixed it and created a pull request.
Fixed by https://github.com/sinhrks/ggfortify/pull/222. Thanks! @axjadamson
@petzi53 Please try out the GitHub version.
No worries! I hope it works okay. xlabs and ylabs can be defined within the ggdistribution function now.
The following code now works perfectly:
ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1, xlab="x axis", ylab="y axis")
My former trial where I used the labs()
function from {ggplot2} still does not work. It does not display "x label" or "y label". But if you use
p <– ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1, xlab="x axis", ylab="y axis")
and then the ggplot additions:
p <- p +
labs(
title = "Title",
subtitle = "subtitle",
caption = "name of the author copyright",
tag = "Plot A",
x = "x label",
y = "y label"
)
p
it ignores the ggplot xlabs and ylabs ("x label" resp. "y label") and uses the former defined "x axis", ylab="y axis" for the graphic.
System information OS Platform and Distribution:macOS Monterey 12.3.1 ggfortify installed from (e.g. CRAN or Github): This time: GitHub ggfortify version: 0.4.14 ggplot2: 3.3.5 R version 4.1.3 (2022-03-10)
@axjadamson Would you like to help take a look at the original use case?
I must admit, I only took a quick look at it and could see that some arguments were missing that would allow labels to be specified with the 'ggdistribution' function, so I updated that. I don't have a deeper understanding of why it won't accept further ggplot additions for x and y axis labels. I would guess that it might be something to do with those arguments being renamed within the ggdistribution function and no longer recognising the ggplot arguments? But I don't know I'm afraid.
No problem. Let's keep this open.
Hello,
with the
ggdistribution()
function x and y labels do not appear.Code to reproduce the issue:
Plot produced by the code:
System information
Thanks, Peter