Open juliabruneau opened 1 year ago
Code chunk I found that is said to work for HTML and PDF knits for getting images side-by-side using include_graphics() of knitr:
{r, echo=FALSE,out.width="49%",
out.height="20%",fig.cap="caption",fig.show='hold',fig.align='center'}
knitr::include_graphics(c("path/to/img1","path/to/img1"))
fig.show='hold'
and fig.align='center'
are used to have the images on the same line
Code chunk I found that is said to work for HTML and PDF knits for getting images side-by-side using include_graphics() of knitr:
{r, echo=FALSE,out.width="49%", out.height="20%",fig.cap="caption",fig.show='hold',fig.align='center'} knitr::include_graphics(c("path/to/img1","path/to/img1"))
fig.show='hold'
andfig.align='center'
are used to have the images on the same line
The issue with include_graphics()
is that it expects the path to a local image, which is why I haven't been successful with the external URL link to the image. If there is a way to get the URL to work with this, this could be a solution! I believe external_img()
that I have above, might have the same issue.
@juliabruneau Apparently urls can be used in place of the paths in include_graphics()
... just wanted to let you know if you're in a spot to test
Using include_graphics()
is giving me an error (doesn't affect the error if I set auto_pdf TRUE/FALSE):
knitr::include_graphics("http://deq1.bse.vt.edu:81/p6/out/river/hsp2_2022/images/fdc.JA4_7280_7340.hsp2_2022.png", "http://deq1.bse.vt.edu:81/p6/out/river/subsheds/images/fdc.JA4_7280_7340.subsheds.png", auto_pdf = FALSE)
Error in external_img(src = x[1], width = fig.width, height = fig.height, :
src must be a string starting with 'rId' or an existing image filename
I've been unable to successfully load the officedown
package to test, getting error I can't decode after installing all dependencies:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Users/glenncampagna/Library/R/4.0/library/rvg/libs/rvg.so':
dlopen(/Users/glenncampagna/Library/R/4.0/library/rvg/libs/rvg.so, 0x0006): tried: '/Users/glenncampagna/Library/R/4.0/library/rvg/libs/rvg.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/glenncampagna/Library/R/4.0/library/rvg/libs/rvg.so' (no such file), '/Users/glenncampagna/Library/R/4.0/library/rvg/libs/rvg.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
Calls: <Anonymous> ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted
but you are close to fixing it @juliabruneau
c('url1','url2')
After changing the knitting to a PDF and not a DOC, the script recognized the filepaths, but then I received a new error regarding the same line of code:
LaTeX Warning: File `http://deq1.bse.vt.edu:81/p6/out/river/hsp2_2022/images/fdc.JA4_7280_7340.hsp2_2022' not found on input line 98.
! LaTeX Error: Unknown graphics extension: .hsp2_2022.
The LaTeX graphics package doesn't recognize files that have multiple periods in the filename. This website talks about possible solutions: https://texfaq.org/FAQ-unkgrfextn
\includegraphics
, and I'm getting these types of errors:
LaTeX Warning: File `http://deq1.bse.vt.edu:81/p6/out/river/hsp2_2022/images/fdc.JA4_7280_7340.hsp2_2022.png' not found on input line 95.
! Package pdftex.def Error: File `http://deq1.bse.vt.edu:81/p6/out/river/hsp2_2022/images/fdc.JA4_7280_7340.hsp2_2022.png' not found: using draft setting.
We can look further into knitting as a PDF, since I don't think knitting as an HTML is the final end product that we are looking for. But right now I'm afraid it is further complicating things.
Can we download images and save them locally, then they are a file not a url? @juliabruneau @glenncampagna
Thoughts in side by side: the ggplot2 method will probably look better for some of the less busy plots like fdc. Maybe a consideration.
Images can be downloaded as usable PNGs using download.file()
and readPNG()
The grid
and gridExtra
packages are useful for arranges images/plots in a grid
grid.arrange()
is able to display the images side-by-side with seemingly better quality than ggplot but they are a bit small as of now:
grid.arrange(rasterGrob(fdc1), rasterGrob(fdc2), ncol = 2)
[x] Enlarge images to check if resolution will work
grid.arrange()
grid.arrange(rasterGrob(fdc1), rasterGrob(fdc2), ncol = 2)
Nice catch @glenncampagna with the rasterGrob()
- that was one of the possible solutions we were thinking about, when trying to overcome the grob object issue!!
This is a separate issue to try to track all the ways we try to display the images from VAHydro side-by-side. See main issue: #659
The Issue:
ggplot()
Methods Thus Far
1. ggplot2
grid.arrange()
ggplot() + annotation_custom()
ggplot() + annotation_raster()
2. ![ ] (url)
cat(fig.fdc)