HARPgroup / HARParchive

This repo houses HARP code development items, resources, and intermediate work products.
1 stars 0 forks source link

Displaying Images Side-By-Side #801

Open juliabruneau opened 1 year ago

juliabruneau commented 1 year ago

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:

Methods Thus Far

1. ggplot2

cat(fig.fdc)


![image](https://user-images.githubusercontent.com/104520318/233186528-c7a9c59b-0f29-4c41-813a-61b79110f6ac.png)

- Based on multiple sources online, using two `![ ](url){width =} ![ ](url){width =}` separated by a space, should display the images side-by-side, but I have not been successful 

### Potential Solutions
- Trying to get method 2. to work
- Investigating [Officeverse ](https://ardata-fr.github.io/officeverse/officedown-for-word.html) more
  - `external_img()`
glenncampagna commented 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

juliabruneau commented 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

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.

glenncampagna commented 1 year ago

@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

juliabruneau commented 1 year ago

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
glenncampagna commented 1 year ago

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

juliabruneau commented 1 year ago

Changing the knitting

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

! 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.
rburghol commented 1 year ago

Can we download images and save them locally, then they are a file not a url? @juliabruneau @glenncampagna

rburghol commented 1 year ago

Thoughts in side by side: the ggplot2 method will probably look better for some of the less busy plots like fdc. Maybe a consideration.

glenncampagna commented 1 year ago

Downloading the images to plot side-by-side in Word

glenncampagna commented 1 year ago

Enlarged FDCs show some decent resolution with downloading the images and using grid.arrange()

image

juliabruneau commented 1 year ago

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!!