g2r icon indicating copy to clipboard operation
g2r copied to clipboard

[Issue] With g2(), subject() is pushing down the plot and hiding the x axis

Open jdunham022 opened this issue 4 years ago • 2 comments

When using subject() with g2(), my plots are being pushed down by the title and my axis is then being hidden (as well as the bottom of the plot). I am just starting out with the g2r package and could possibly be doing something incorrectly. Below is a simple plot with subject() being used. I have attached two pictures showing my output of the below code. One is with subject("Plot Title"), and the other is without subject() being used.

dat <- mtcars %>%
  mutate(car = rownames(mtcars)) %>%
  head(6)

g2(dat, asp(x = car, y = mpg)) %>%
  fig_interval() %>%
  subject("Plot Title")

with_subject without_subject

jdunham022 avatar May 13 '21 19:05 jdunham022

I think this is a corner case caused by an option to display the visualisation over the entire browser/viewer.

As a workaround you can set the height of the plot in pixels (defaults to 100%).

# set height
g2(dat, asp(x = car, y = mpg), height = 500) %>%
  fig_interval() %>%
  subject("Plot Title")

It should work fine in Rmarkdown, let me know if it does not.

JohnCoene avatar May 13 '21 20:05 JohnCoene

Thank you for the quick response. Your solution does with within RStudio and the RStudio Viewer, but once knitted to an html document (I am using flexdashboard), the problem persists. I messed around with different {data-height} values with flexdashboard as well as different pixel values within g2, and am still coming up empty.

Thanks again for the help.

jdunham022 avatar May 13 '21 21:05 jdunham022