0

Trying to learn ggiraph, experimenting with basic examples.

I'm using R 4.0.2 and RStudio 1.3.1073, both freshly downloaded & updated on my Win10 machine.

library( tidyverse )
library( ggiraph )

somePlot <- 
  mtcars %>% 
  mutate( carname = rownames( . ) ) %>% 
  ggplot( aes( x = wt, y = qsec, color=disp,
               tooltip = cyl, data_id=carname ) ) +
  geom_point_interactive( ) +
  theme_bw()

somePlot                     # Shows ggplot object as expected, no interactivity

girafe( ggobj = somePlot )   # Interactivity, but viewing window shows only about top 2/3 of plot

Links to images because I don't yet have enough reputation on StackOverflow to qualify for posting images:

ggplot object in zoomed viewing window

girafe object in zoomed viewing window

For each image, I clicked "Zoom" in the RStudio plot-viewing window, then captured the image to a PNG file. Expanding the zoom window has no effect-- the ggiraph plot is still truncated at the same place.

If images don't appear: the somePlot call produces a graph as I expect... I can see the entire y axis as well as the x-axis and its labels.

The girafe... call produces the upper 2/3 or so of the graph... I cannot see the x-axis at all, and I cannot see the full extent of the y-axis. The plotted points have the interactivity I expect when I hover over them.

Any ideas about how I might fix this?

1 Answers1

0

Simple fix as suggested by David Gohel: Resize the viewing window -- either the Viewer panel inside RStudio or the window that's opened with the Zoom button. In particular, change the aspect ratio of the viewing window to reveal more (or less) of the figure.

I guess I was expecting the viewing window to behave similarly to base graphics or ggplot, where the displayed image is sized to fit the viewing window, and resizes when the window is resized.

Instead, ggiraph appears to create the image at the size it likes, and if your viewing window doesn't match the aspect ratio of the figure, then some of the figure will spill out of the viewing window.

Thanks.

  • It's not the size it likes, it documented and can be changed: https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#size-options-1 – David Gohel Aug 22 '20 at 07:41