Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf() device transparency problems with shape = "outline" #23

Open
hughjonesd opened this issue Jan 31, 2024 · 10 comments
Open

pdf() device transparency problems with shape = "outline" #23

hughjonesd opened this issue Jan 31, 2024 · 10 comments

Comments

@hughjonesd
Copy link
Owner

hughjonesd commented Jan 31, 2024

I just tested the "Texas" commands and I see that it works for PDF but not PNG Device.

However, while the transparency of the backbround of the PDF version is achieved, the Texas state itself is not colored red. With shadow = TRUE there is a gray coloring inside. With shadow = FALSE there is only the orange outline. I colored the rest of the states "green4" with "yellow" lines to make the image different. Here are the PDF (Device) output using pdf(file="Texasplot2.pdf") and dev.off():

texas2

(Saving to PNG looks the same as the one on the first comment, with a red Texas but blue neighbours.)

Originally posted by @jsgro in #22 (comment)

@hughjonesd
Copy link
Owner Author

Bug checks out on my machine too. Using bg = "white" in the pdf call doesn't fix it.

@hughjonesd
Copy link
Owner Author

shape = "rect" and "ellipse" both work OK with PDF, so it must be specific to the "outline".

@hughjonesd hughjonesd changed the title PDF device transparency problems? PDF device transparency problems with shape = "outline" Jan 31, 2024
Repository owner deleted a comment from jsgro Jan 31, 2024
@hughjonesd
Copy link
Owner Author

The problem is not border_grob replacing the colour with transparency. Seems to be to do with the mask grob; setting mask_grob = FALSE works fine but then obviously leaves a square inset.

@hughjonesd
Copy link
Owner Author

hughjonesd commented Jan 31, 2024

A workaround on Mac is to use the cairo_pdf() device, which works nicely. That may also work on other platforms where it is supported.

My guess is that the original pdf() device lacks some of the compositing options mentioned in dev.capabilities().

@hughjonesd hughjonesd changed the title PDF device transparency problems with shape = "outline" pdf() device transparency problems with shape = "outline" Jan 31, 2024
Repository owner deleted a comment from jsgro Jan 31, 2024
Repository owner deleted a comment from jsgro Jan 31, 2024
@hughjonesd
Copy link
Owner Author

Added documentation on recommended graphics devices in the help file. Leaving this open for others to find.

@jsgro
Copy link

jsgro commented Feb 1, 2024

Thanks for keeping this open... Glad you added the paragraph Graphics devices under Tips and tricks. I followed the information and here are suggestions to clarify the text:

  • the package is called ragg (install.packages('ragg') as trying to install ragg_png causes error.)
  • the command is not ragg_png but agg_png as I found in the ragg package README.html

I think that having this information at the Top of the README file would be useful as other people might not realize agg_png was the device used. While this creates the best image, most users would not know about it...

I see that there are other options within that package for other formats and has great features (speed, font access etc.) Well worth the discovery! Thanks. JYS

@hughjonesd
Copy link
Owner Author

Yes, but from knitr the device option must be set to "ragg_png" (and no, I don't know why this name was chosen...) See README.Rmd source for an example.

@jsgro
Copy link

jsgro commented Feb 1, 2024

I love knitr, bookdown and all of these packages!
However, when teaching or discovering a new package (such as yours this week) in e.g. a class setting it is usually easier to either type on the console or work from an R script file. In that case we would not use knitr methods until those students learn a bit more about markdown and Rmarkdown and the related concepts.
Therefore the "standard" way to use this ragg package would be to create a plot object, and then use the more standard approach to open/close the file. For example:

library(ragg)
agg_png(file="Texasplot_ragg.png")
ggpm_w_inset # ggplot object with inset
dev.off()

> I don't know why this name was chosen...

I found that ragg_png is defined as a function within the plot.R file within the knitr package as such on lines 113-116:

    # similar to load_device(), but the `dpi` argument is named `res`
    ragg_png = function(...) {
      ragg::agg_png(..., res = dpi, units = 'in')
    },

I still believe that the "standard" method should be clearly mentioned, perhaps with the link to the ragg package README.html for those using knitr.
Best - JYS

@hughjonesd
Copy link
Owner Author

You can't hold people's hands too much. Otherwise, you just end up reproducing other packages' documentation. Then you have increased the burden on yourself, and when the other package updates, your docs are inaccurate. It's fine to expect people to figure out agg_png/ragg_png by themselves.

@hughjonesd
Copy link
Owner Author

Also again, no offence, but this is an issue tracker, not a forum. I didn't notice till now, but this question is completely irrelevant to this issue. That makes it harder for me to track the state of play for the actual bug. Please keep issues separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants