I include two ggplotly() graphics in a html file, eg.
library(ggplot2)
library(plotly)
library(htmltools)
g1 <- ggplot(data=data.frame(x=1:10, y=1:10)) +
geom_point(aes(x=x, y=y))
g2 <- ggplot(data=data.frame(x=11:20, y=1:10)) +
geom_point(aes(x=x, y=y))
l1 <- ggplotly(g1)
l2 <- ggplotly(g2)
htmltools::save_html(htmltools::tagList(l1,l2), file ="index.html")
And now want to include an image in the same html file,eg a ggplot2 object:
foto <- imresize(load.image(system.file("ex/logo.tif", package="terra")),0.25)
fotodf <- as.data.frame(foto,wide="c") %>% mutate(rgb.val=rgb(c.1,c.2,c.3))
p <- ggplot(fotodf,aes(x,y))+geom_raster(aes(fill=rgb.val)) + scale_fill_identity() +
scale_y_reverse() + coord_fixed() + theme_void()
or insert the image file into the html file directly.
The problem is that I do not find how to insert either the p ggplot object
or the logo.tif file into index.html
2
Answers
Many thanks, extremely useful. As I need the image to be another graphic rather than an overlay (using the logo is just for an example), I've modified your code to:
which results into:
I'd appreciate a link to doc on the actual "style" definitions. I still get the image left-aligned while I try to put it at the center of its quadrant.
We could do something like this: