Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no x/y labels with ggdistribution plots #218

Open
petzi53 opened this issue Feb 14, 2022 · 12 comments
Open

no x/y labels with ggdistribution plots #218

petzi53 opened this issue Feb 14, 2022 · 12 comments

Comments

@petzi53
Copy link

petzi53 commented Feb 14, 2022

Hello,

with the ggdistribution() function x and y labels do not appear.

Code to reproduce the issue:

p <- ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1)

p <- p +
    labs(
    title = "Title",
    subtitle = "subtitle",
    caption = "name of the author copyright",
    tag = "Plot A",
    x = "x label",
    y = "y label"
) 
p

Plot produced by the code:

xlab-problem


System information

  • OS Platform and Distribution:macOS Monterey 12.1
  • ggfortify installed from (e.g. CRAN or Github): CRAN
  • ggfortify version: 0.4.14
  • ggplot2: 3.3.5
  • R: 4.1.2 (2021-11-01)

Thanks,
Peter

@terrytangyuan
Copy link
Collaborator

Thanks for reporting this. Have you tried this on older versions of ggplot2?

@petzi53
Copy link
Author

petzi53 commented Feb 14, 2022

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.

@terrytangyuan
Copy link
Collaborator

The relevant code looks correct to me

p <- ggplot2::ggplot(mapping = mapping) +
ggplot2::scale_x_continuous(name = xlab) +
ggplot2::scale_y_continuous(name = ylab)
}

Could you try the following?

ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1, xlab="x axis", ylab="y axis")

@petzi53
Copy link
Author

petzi53 commented Feb 16, 2022

It reports an error:

Error in func(x, ...) : 
  unused arguments (xlab = "x axis", ylab = "y axis")

@axjadamson
Copy link
Contributor

Just to say, I'm having the same issue and get the same error as petzi53

@axjadamson
Copy link
Contributor

Okay I fixed it and created a pull request.

@terrytangyuan
Copy link
Collaborator

Fixed by #222. Thanks! @axjadamson

@petzi53 Please try out the GitHub version.

@axjadamson
Copy link
Contributor

No worries! I hope it works okay. xlabs and ylabs can be defined within the ggdistribution function now.

@petzi53
Copy link
Author

petzi53 commented Apr 12, 2022

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)

@terrytangyuan
Copy link
Collaborator

@axjadamson Would you like to help take a look at the original use case?

@axjadamson
Copy link
Contributor

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.

@terrytangyuan terrytangyuan reopened this Apr 12, 2022
@terrytangyuan
Copy link
Collaborator

No problem. Let's keep this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants