Why do some waffle chart glyphs work but not others? - r

I have installed fontawesome ttfs onto my local machine and loaded them into R. When I test this using fonts()[grep("Awesome", fonts())] it returns "FontAwesome" as expected.
I can run a waffle chart with certain glyphs... so far male, female, and briefcase have worked, but not others, such as "building."
Any idea what's going on?
library(ggplot2)
library(fontawesome)
library(extrafont)
library(waffle)
# This works fine
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "female", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)
# This does not work
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)

Not sure exactly why it is happening for some glyphs but not others, but I ran across the same issue recently. Found an excellent how-to here: https://www.listendata.com/2019/06/create-infographics-with-r.html
It sounds like you already have fonts available so could skip the first part of the how-to, and that you may just be missing packages. You'll want to add two others: echarts4r (on CRAN) and echarts4r.assets (on github only as of now)
require(devtools)
devtools::install_github("JohnCoene/echarts4r.assets")
library(tidyverse)
library(waffle)
library(extrafont)
library(echarts4r.assets)
library(echarts4r)
# Works for me with all of these packages loaded
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)

Related

How to put legends at the bottom of the heatmap,still not solved?

[ Reference: <Evolutionary origins of the SARS-CoV-2 sarbecovirus lineage responsible for the COVID-19 pandemic(extended fig.5),Using the code from https://github.com/TD-lab-Wu/SARSCoV2origins>]
[3 differences :
Question1:how to make the legend on the bottom of the picture by using the packege pheatmap?
Question2:how to make the slight margin between the cells?
Q3.How to draw the 4 horizontal lines for the 4 clusters?
]
Here is the code from the paper:
install.packages("tidyverse")
library(pheatmap)
library(viridis)
library(ggrepel)
library(ggpmisc)
library(rlang)
# RSCU Heatmap ------------------------------------------------------------
all_rscu = read.csv("https://raw.githubusercontent.com/plemey/SARSCoV2origins/master/codonUsage/all_rscu_codonBiasReanalysis.csv")
all_df <- as.data.frame(all_rscu[,2:26])
row.names(all_df) <- all_rscu$codon
pheatmap(all_df,
cluster_rows = F,
gaps_row = c(10, 14),
scale = 'none',
fontsize_row = 5,
fontsize_col = 10,
color = magma(50),
border_color = NA,
cutree_cols = 4
)
I check the pheatmap in the CRAN,so many functions,but i did not find one way to fix these problems,and this is the same question when i look for answer in the stackoverflow,https://stackoverflow.com/questions/63951276/how-to-put-key-values-and-legends-at-the-bottom-of-the-heatmap
Best Regards

Is there a way in gt() to remove the strange white border around the table when I export it using R?

I am trying to export this gt table in R that needs to have a specific background color because the slides I am using in PowerPoint already have that background color. However, when I use gtsave(), it creates this weird white border around the colored background. Here is the code I am using...what am I missing?
library(tidyverse)
library(gt)
gtDF <- tibble(a = c(LETTERS),
b = 1:26) %>%
gt() %>%
tab_options(table.font.names = 'Century Gothic',
table.background.color = "#ECF5F8",
column_labels.background.color = '#ECF5F8',
column_labels.font.weight = 'bold',
heading.title.font.weight = 'strong',
heading.title.font.size = 14,
table.font.color = '#1a1364',
source_notes.font.size = 14,
table.font.size = 14)
gtsave(gtDF, 'gtDF.png')
gtsave(gtDF, 'gtDF.png', expand = 0)
should get rid of the white border. If you want to add borders to the table with predefined colors you can add things like
table.border.top.width=10,
table.border.top.color='#ECF5F8',
etc. to your tab_options.
Probably not what you are looking for as this answer does not use gt options. It's likely possible, but I don't know how to do it. So here's a workaround using the package magick:
Note: The pink borders are just to help visualize the effect.
library(tidyverse)
library(gt)
library(magick)
#> Linking to ImageMagick 7.0.11.11
#> Enabled features: cairo, fontconfig, freetype, heic, lcms, pango, raw, rsvg, webp, x11
#> Disabled features: fftw, ghostscript
#> Using 4 threads
gtDF <- tibble(a = c(LETTERS),
b = 1:26) %>%
gt() %>%
tab_options(table.font.names = 'Century Gothic',
table.background.color = "#ECF5F8",
column_labels.background.color = '#ECF5F8',
column_labels.font.weight = 'bold',
heading.title.font.weight = 'strong',
heading.title.font.size = 14,
table.font.color = '#1a1364',
source_notes.font.size = 14,
table.font.size = 14,
table.border.top.color = '#30DB34')
gtsave(gtDF, 'gtDF.png')
png <- image_read('gtDF.png')
image_border(png, "hotpink", "5x5")
image_write(image_trim(png), 'gtDF_wo_border.png', format = 'png')
png2 <- image_read('gtDF_wo_border.png')
image_border(png2, "hotpink", "5x5")

Ghostscript/ embed_fonts() never stops

I want to create a R-plot that uses the font Latin Modern Roman and export it as pdf.
I've found the package extrafont that provides such additional fonts. At first, I had some issues with Ghostscript, which was not installed on my computer and after installation was not found. Providing R with the complete path to the .exe like this Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.52/bin/gswin64.exe"), however, fixed the problem. Similar to many examples I've found on the internet, I then wrote the following script*:
require("extrafont")
loadfonts(device = "win")
dat <- data.frame(x = seq(1, 20), y = c(
1, 2, 4, 5, 7, 8, 9, 11, 21, 43, 30, 91, 100, 200, 238, 490, 700, 900, 920, 1000
))
file <- paste(fig_dir, "/test.pdf", sep = "")
pdf(file = file, width = 5, height = 5*0.75)
par(family = "LM Roman 10")
plot(x~y, data = dat, main = "LaTeX Font Plot", ylab = "y-lab", xlab = "This is the x-label")
dev.off()
embed_fonts(file = file, outfile = str_replace(file, ".pdf", "_embed.pdf"))
Here, fig_dir is the directory to a folder containing the exported figures.
The first problem is a warning message telling me that the width of symbol 0x2d is unknown. Nevertheless, the .pdf is exported. The main issue, however, is the subsequent embed_fonts() command, because it simply runs forever. Unfortunately, I won't get any error messages, I just never get a result. Maybe someone has a hint where the problem could be or even faced a similar problem?
*the fonts were previously installed:
font_import(prompt = FALSE, pattern = "lmroman")
loadfonts(device = dev)

Odd ReporteRs issue with pipe %>%

I am having an odd issue with ReporteRs all of a sudden, even though I haven't updated or installed any new packages since the last time my code worked fine.
It seems to be related to the pipe operator. Here is an example:
This code returns this very general error, and I am sure it worked on the same table object a couple of weeks ago:
Indeed re-writing the code without pipes works:
I get the same issue with other commands too, such as addParagraph, addSlide, etc, but only when chained through the pipe operator.
Here is the session info. Has anybody come across this issue, and can suggest a solution?
Note my analysis work takes place in a safe haven environment that is not connected to the internet, hence not being able to have much control over what software versions are installed (and providing screenshot only).
EDIT: Code used:
paired_outcomes2 <- data.frame(sample = as.factor("Service"), percentage = as.character("50%"), count = as.integer(30))
# works
MyFTable <- paired_outcomes2
# The table
MyFTable <- FlexTable(MyFTable, add.rownames = FALSE, header.columns = F,
header.cell.props = cellProperties( background.color = "white" ),
header.text.props = textProperties( color = "black",
font.size = 11, font.weight = "bold" ),
body.text.props = textProperties( font.size = 10 , font.family="Calibri"))
# doesn't work
MyFTable <- paired_outcomes2 %>%
# The table
FlexTable( add.rownames = FALSE, header.columns = F,
header.cell.props = cellProperties( background.color = "white" ),
header.text.props = textProperties( color = "black",
font.size = 11, font.weight = "bold" ),
body.text.props = textProperties( font.size = 10 , font.family="Calibri"))
Ah I found the reason! The package 'sets' for some reason disrupts the ReporteRs commands that use pipes, so detaching it (I don't normally use it but had on this occasion) fixes the issue.

Plotting with Vennerable package in R

Here is a very basic example:
library(vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
plot(srl.venn)
All I'm trying to do is to remove borders around circles, and format colors and fonts. However, still haven't done much.
Could you please share any useful examples?
Check out VennThemes for changing parameters within the plot. For example:
library(Vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
srl.venn.c <- compute.Venn(srl.venn, doWeights=T)
gp <- VennThemes(srl.venn.c, colourAlgorithm = "binary")
plot(srl.venn.c, gpList = gp, show = list(FaceText = "signature", SetLabels = FALSE,
Faces = FALSE, DarkMatter = FALSE))
More detail can be found in the man pages or by calling vignette("Venn")

Resources