How best to output interactive ggplot graphs for screen size and readability like a normal ggplot?

Hello!

I have this really simple plot example below using ggiraph to make it interactive. I have seen that this. You will see that in the example below we run gg_crime which is the ggplot version and finally the interactive one via girafe.

My question is - how to best control ggiraph output?. With ggplot I can decide on the graphics device etc to save the plot and make a really large DPI etc. I am able to control the width and height of the animated plot but I want to know how best I can control all other things such a DPI etc as I want to optimise this plot (my real problem has a really complex dendrogram with over 90 entries) and I want to optimise it for viewing at 1920 x 1080.

Any recommendations on how best to achieve this? Even if I could get the animated plot to inherent the original ggplot elements I would be glad cause as you can see the outputs are not the same with defaults.

library(ggplot2)
library(ggiraph)
#> Warning: package 'ggiraph' was built under R version 4.1.2


crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
head(crimes)
#>                 state Murder Assault UrbanPop Rape
#> Alabama       alabama   13.2     236       58 21.2
#> Alaska         alaska   10.0     263       48 44.5
#> Arizona       arizona    8.1     294       80 31.0
#> Arkansas     arkansas    8.8     190       50 19.5
#> California california    9.0     276       91 40.6
#> Colorado     colorado    7.9     204       78 38.7


# create an 'onclick' column
crimes$onclick <- sprintf("window.open(\"%s%s\")",
                          "http://en.wikipedia.org/wiki/", as.character(crimes$state) )

gg_crime <- ggplot(crimes, aes(x = Murder, y = Assault, color = UrbanPop )) + 
  geom_point_interactive(
    aes( data_id = state, tooltip = state, onclick = onclick ), size = 3 ) + 
  scale_colour_gradient(low = "#999999", high = "#FF3333")

gg_crime

girafe(ggobj = gg_crime)

Created on 2022-03-19 by the reprex package (v2.0.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.