daattali / ggExtra

📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements
http://daattali.com/shiny/ggExtra-ggMarginal-demo/
Other
383 stars 45 forks source link

X-axis label too close to edge of plot - need a bit of margin because some letters get cut off #49

Closed daattali closed 7 years ago

daattali commented 7 years ago

At some point in the past year, the bottom margin of the x axis label has disappeared. The label is stuck to the bottom of the image without any space, and any letters that go lower the the standard line (such as "g" "j" "p" "q" "y") are cut off.

I'm not sure if this is because of newer ggplot version, or because of the refactoring from https://github.com/daattali/ggExtra/pull/26

crew102 commented 7 years ago

Hmm, is this what you are talking about?

temp

It looks like there is zero margin around the x and y axis (both in refactored version and non. Note, this is the refactored version). I'm not getting any letters cut off in either version, though. Should we add padding around the plot?

daattali commented 7 years ago

Looks like it might be an RStudio Viewer issue maybe? Running this code:

p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()
ggMarginal(p + xlab("gpjy"))

I get this in rstudio

image

But if I export the image, then the bottom is not cut off. You don't get that in rstudio?

crew102 commented 7 years ago

Incidentally I just updated to R 3.4.0 today and the RStudio version I run doesn't support the latest version of the R graphics engine that is used in 3.4.0. However, using graphics engine version 2 I still don't get cutoff:

1

I think it's probably the ggplot2 version that's doing it. What version are you using? I'm at 2.2.1.

It also looks like you're getting plenty of margin space for the y-axis, which mine doesn't show.

daattali commented 7 years ago

I'm also at ggplot2 2.2.1

If we can't find the exact cause for these discrepancies easily, I wouldn't bother with it too much at this time. It's good to have this documented and we can come back to it later

crew102 commented 7 years ago

I think I see what's going on here... This is using RStudio v 1.0.143:

untitled

Looks like when the plot is confined to the "Plots" tab as it is on the right hand side, the x-axis title is getting cut off. When you "zoom" (or print to a device - e.g., pdf, png) as is shown on the left hand side, something happens with the sizing of the graph where we don't see the problem.

I think we should add padding, as most people will view plots interactively through the plots tab and will wonder why it's getting cut off.

Also, there's this: https://support.rstudio.com/hc/en-us/articles/200488548-Problem-with-Plots-or-Graphics-Device

crew102 commented 7 years ago

Strangely enough the Plots tab in RStudio server doesn't seem to have the issue that the desktop version does - at least for the graphs I've looked at.

daattali commented 7 years ago

I'm fairly convinced this is indeed an RStudio bug. Adding very minimal padding could be a good idea

daattali commented 7 years ago

Did you add this minimal bottom padding to #40 ?

crew102 commented 7 years ago

Going to address in separate PR

daattali commented 7 years ago

Sounds good