How to ensure all fonts are written in Arial for EnhancedVolcano?
1
0
Entering edit mode
22 months ago
junli1988 • 0

As the title, I need to wrangle the plot so that all the words are typed in the font style of Arial. How do I do that? Sorry for the late edit. This question was meant for the EnhancedVolcano plot package.

EnhancedVolcano • 3.4k views
ADD COMMENT
1
Entering edit mode

Since Enhanced volcano is based on ggplot2, ggplot2 options might be working over enhanced volcano object Try this:

  1. Install extrafont package
  2. Import fonts
  3. Use 'family' option in theme as below

=

library(extrafont)
font_import()
library(ggplot2)
fonts()
p1=ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme_bw() +
  theme(text=element_text(family="Comic Sans MS", size=14))

p2=ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme_bw() +
  theme(text=element_text(family="Arial", size=14))

library(patchwork)
p1+p2

Rplot

If you have problems in importing fonts, try font_import after installing 'remotes::install_version("Rttf2pt1", version = "1.3.8")'

ADD REPLY
0
Entering edit mode

To make this question more legible/get a greater audience, you should

  • (a) mention the package in the header and body of the question
  • (b) describe in more detail which part of the labeling you're having issues with -- ideally post a picture of your output because in my experience, EnhancedVolcano uses the standard font family without serifs ("sans") and it may very well be a setting on your end that leads to the unexpected outcome
  • (c) if you've tried anything to solve the issue, you should mention that, too

I'm relatively certain that we could help you here, but you need to be more specific about which part of the labels you're actually taking issue with.

ADD REPLY
0
Entering edit mode

Past threads that are related to fonts for EnhancedVolcano that may be useful:

Enhanced volcano: how to italicize or change the font of legend?

ADD REPLY
0
Entering edit mode
22 months ago

Just in case other users happen to encounter similar issues, here are my five cents on the topic:

Looking at the EnhancedVolcano() code, I don't see why there would be different fonts in the labels; they should all have the same basic font (which may or may not be Arial-like; see below) because the main function seems to rely on bquote() and ggplot2::geom_text() for generating the labels.

ggplot2::geom_text() uses the "sans" family of fonts per default. You can learn a lot about the details in the documentation and here To find out which font will be used on your computer for the "sans" entry, you can try X11Fonts()$sans if you're working on a Mac or Linux-based OS. More here

In my case, the output looks like this:

> X11Fonts()$sans
[1] "-*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"

Therefore, my plots are labeled with Helvetica, which is essentially Arial (see below for more on that).

You could indeed ask the author of EnhancedVolcano to expose the font family parameter of ggplot2::geom_text() to the user -- this is best done via github --> issues where you can ask for a new feature with the package.

A quicker solution may be to try the base R PDF export function with specifying the font family:

ggp <- EnhancedVolcano(...)

pdf("ggp.pdf", family = "Helvetica")                  # Apply pdf function
print(ggp)
dev.off()

However, pdf() typically offers support for standard Adobe fonts (and URW equivalents), which does NOT include Arial (the closest will be Helvetica -- I dare the reviewer to spot the difference although they do exist)

From help(pdf):

these are fonts you can specify via the family parameter: "AvantGarde",  "Bookman",  "Courier",  "Helvetica",  "Helvetica-Narrow",  "NewCenturySchoolbook",  "Palatino" and "Times"; "URWGothic",  "URWBookman", "NimbusMon", "NimbusSan" (synonym "URWHelvetica"), "NimbusSanCond", "CenturySch", "URWPalladio" and "NimbusRom" (synonym "URWTimes").

This also means that even if EnhancedVolcano exposed the ggplot2::geom_text() parameter to change the font family manually, you'd be stuck with whatever is available on your system. If you truly want to go down the rabbit hole of installing additional fonts, you will have to look into additional packages, such as extrafont. I do not recommend this, though.

In brief: Make sure your settings for the "sans" family specify "Helvetica" (or "Arial", of course).

The easiest solution, btw, might be to simply specify your own labels via EnhancedVolcano's xlab, ylab, subtitle parameters because I'm suspecting that the issue the reviewer has may be with the use of bquote as the default setting and the subsequent proper display of mathematical notation which some reviewers may not be used to anymore. However, even those font settings simply rely on your environment setting:

The fonts used are taken from the current font family, and so can be set by par(family=) in base graphics, and gpar(fontfamily=) in package grid.

Reference: plotmath docu

ADD COMMENT

Login before adding your answer.

Traffic: 2707 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6