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

Figure size not respected when axis lines not visible #136

Open
MonikaFu opened this issue Nov 17, 2022 · 4 comments
Open

Figure size not respected when axis lines not visible #136

MonikaFu opened this issue Nov 17, 2022 · 4 comments
Labels
help wanted Extra attention is needed priority

Comments

@MonikaFu
Copy link
Collaborator

MonikaFu commented Nov 17, 2022

For some reason, Rmd/Latex decides to disregard plot dimensions when a void theme is used (or axis lines are made not visible).

Both this code:

{r alignment_table_equity, fig.height=4, fig.width=6, fig.align='center'}
empty_plot_no_data_message <- function() {
  p <- ggplot() +
    annotate(
      "text",
      label = "No data were found\nto create this plot",
      x = 0.5,
      y = 0.5,
      size = 6
    ) +
    coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
    theme_classic() +
    theme(
      axis.line = element_line(colour = "#FFFFFF"),
      axis.ticks = element_blank(),
      axis.text = element_blank(),
      axis.title = element_blank()
    )
  p
}
empty_plot_no_data_message()

and this code:

{r alignment_table_equity, fig.height=4, fig.width=6, fig.align='center'}
empty_plot_no_data_message <- function() {
  p <- ggplot() +
    annotate(
      "text",
      label = "No data were found\nto create this plot",
      x = 0.5,
      y = 0.5,
      size = 6
    ) +
    coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
    theme_void()
  p
}
empty_plot_no_data_message()

results in the plot dimensions being cut and the empty plot is squeezed in on one page with the other plot.
image

in contrast to when the axis are visible:

{r alignment_table_equity, fig.height=4, fig.width=6, fig.align='center'}
empty_plot_no_data_message <- function() {
  p <- ggplot() +
    annotate(
      "text",
      label = "No data were found\nto create this plot",
      x = 0.5,
      y = 0.5,
      size = 6
    ) +
    coord_fixed(xlim = c(0, 1), ylim = c(0, 1)) +
    theme_classic()
  p
}
empty_plot_no_data_message()

Code above results in this output (desired):
image

@AlexAxthelm maybe you can help with this.

@MonikaFu MonikaFu added help wanted Extra attention is needed priority labels Nov 17, 2022
@AlexAxthelm
Copy link
Collaborator

Huh. That's weird. I'll see if anything changes when I start putting stuff into LaTeX boxes.

As a hacky workaround, maybe we set axis & text color to white, so it's there, but invisible?

@MonikaFu
Copy link
Collaborator Author

@AlexAxthelm I tried your suggestion already, see the first chunk of code in the description. Doesn't work.

@AlexAxthelm
Copy link
Collaborator

AlexAxthelm commented Nov 17, 2022

Well, that's even weirder. I'll keep trying it from the LaTeX side.

does axis.line = element_line(colour = "#FFFFFE"), work?

@MonikaFu
Copy link
Collaborator Author

no, that's exactly what I tried :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed priority
Projects
None yet
Development

No branches or pull requests

2 participants