I used ggplot2 to draw the picture, the label contains the Greek letter $\sigma_{aa}^2$, $\sigma_{ad}^2$, $\sigma_{dd}^2$, $\sigma_{d}^2$, and I set the family as "family = "Times New Roman". However, after I exported, the family of $\sigma_{aa}^2$, $\sigma_{ad}^2$, $\sigma_{dd}^2$, $\sigma_{d}^2$ turned to Symbol. I had to manually change its family to "Times New Roman" in ppt to ensure normal display.



My code:
library(ggplot2)
library(dplyr)
library(export)
library(extrafont)
loadfonts(device = "win")
generic_variance_breed_ratio4 <- read.csv("./generic_variance_breed_ratio4.csv")
subTraits <- c("PH_V6", "SLW_V6", "SLW", "DTA", "DTS", "ASI", "abs_ASI", "PH", "EH", "ELL", "ELW","ELA","SPW", "Yield", "EL", "ED", "RNPE", "KNPR", "HGW")
plots <- list()
for(trait in subTraits){
data <- generic_variance_breed_ratio4[,c(colnames(generic_variance_breed_ratio4[1]),trait)]
colnames(data) <- c("components","value")
data <- data %>% mutate(components = factor(factor(components,levels = c("aa","ad","dd","d"))))
data <- data %>% arrange(components)
label_colors <- c(
"aa" = "white",
"ad" = "black",
"dd" = "white",
"d" = "black"
)
data <- data %>%
arrange(desc(components)) %>%
mutate(
prop = value / sum(value) * 100,
ypos = cumsum(prop) - 0.5 * prop,
# formula_part = sapply(components, function(x) as.character(formula_labels[[x]])),
text_color = label_colors[components]
)
data$formula_part <- c(
bquote(atop(sigma[d]^2,.(sprintf("%.1f%%",data[data$components=="d",]$prop)))),
bquote(atop(sigma[dxd]^2,.(sprintf("%.1f%%",data[data$components=="dd",]$prop)))),
bquote(atop(sigma[axd]^2,.(sprintf("%.1f%%",data[data$components=="ad",]$prop)))),
bquote(atop(sigma[axa]^2,.(sprintf("%.1f%%",data[data$components=="aa",]$prop))))
)
custom_colors <- c(
"aa" = "#800080",
"ad" = "#FFC0CB",
"dd" = "#0000FF",
"d" = "#FFFFFF"
)
p <- ggplot(data, aes(x = "", y = prop, fill = components)) +
geom_bar(
stat = "identity",
width = 1,
color = "black"
) +
labs(title = paste("Relative contributions of the genetic components of MPH for",trait))+
coord_polar("y", start = 0) +
scale_fill_manual(values = custom_colors) +
geom_text(
aes(
y = ypos,
label = formula_part,
color = text_color
),
size = 5,
family = "Times New Roman",
vjust = 0.5,
parse = TRUE
) +
scale_color_identity()+
theme_void() +
theme(
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
legend.position = "none",
text = element_text(family = "Times New Roman", size = 12),
)
plots[[trait]] <- p
}
width_inch <- 18 / 2.54
height_inch <- 10 / 2.54
aspect_ratio <- 0.5
height_inch <- width_inch * aspect_ratio
file_path <- "Relative contributions of the genetic components of MPH.pptx"
if (file.exists(file_path)) {
file.remove(file_path)
}
invisible(
lapply(plots, function(p) {
graph2ppt(p,
file = file_path,
append = TRUE,
paper="A4",
orient="portrait",
width = width_inch,
height = height_inch,
# fonts = "Times New Roman",
)
})
)
sessionInfo()
>sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936 LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gdtools_0.2.3 extrafont_0.19 export_0.3.0 dplyr_1.1.1 ggplot2_3.4.2
loaded via a namespace (and not attached):
[1] MatrixGenerics_1.2.1 Biobase_2.50.0 tidyr_1.3.0 jsonlite_1.8.8
[5] stargazer_5.2.3 shiny_1.6.0 stats4_4.0.2 GenomeInfoDbData_1.2.4
[9] Rsamtools_2.6.0 devEMF_4.4-1 Rttf2pt1_1.3.12 pillar_1.9.0
[13] backports_1.4.1 lattice_0.20-41 glue_1.6.2 extrafontdb_1.0
[17] uuid_1.1-0 digest_0.6.27 manipulateWidget_0.11.1 promises_1.1.1
[21] GenomicRanges_1.42.0 XVector_0.30.0 colorspace_2.0-0 httpuv_1.5.5
[25] htmltools_0.5.1.1 Matrix_1.2-18 XML_3.99-0.5 pkgconfig_2.0.3
[29] broom_1.0.4 zlibbioc_1.36.0 xtable_1.8-4 purrr_1.0.1
[33] scales_1.2.0 later_1.3.1 openxlsx_4.2.5 officer_0.3.16
[37] BiocParallel_1.24.1 tibble_3.2.1 farver_2.0.3 generics_0.1.3
[41] IRanges_2.24.1 ellipsis_0.3.2 withr_2.5.2 SummarizedExperiment_1.20.0
[45] BiocGenerics_0.36.1 cli_3.6.1 mime_0.12 magrittr_2.0.3
[49] crayon_1.5.2 evaluate_0.23 fansi_0.4.1 xml2_1.3.3
[53] tools_4.0.2 data.table_1.14.2 lifecycle_1.0.4 matrixStats_0.58.0
[57] flextable_0.6.3 S4Vectors_0.28.1 munsell_0.5.0 zip_2.1.1
[61] DelayedArray_0.16.2 Biostrings_2.58.0 compiler_4.0.2 GenomeInfoDb_1.26.7
[65] systemfonts_1.0.4 rlang_1.1.0 grid_4.0.2 RCurl_1.98-1.2
[69] rstudioapi_0.15.0 htmlwidgets_1.5.3 miniUI_0.1.1.1 crosstalk_1.2.1
[73] labeling_0.4.3 bitops_1.0-6 base64enc_0.1-3 rmarkdown_2.21
[77] gtable_0.3.4 R6_2.5.1 GenomicAlignments_1.26.0 rvg_0.2.5
[81] knitr_1.46 rtracklayer_1.50.0 fastmap_1.1.0 utf8_1.1.4
[85] stringi_1.5.3 parallel_4.0.2 Rcpp_1.0.8.3 vctrs_0.6.1
[89] rgl_0.105.13 tidyselect_1.2.0 xfun_0.44
I used$\sigma_{aa}^2$ , $\sigma_{ad}^2$ , $\sigma_{dd}^2$ , $\sigma_{d}^2$ , and I set the family as $\sigma_{aa}^2$ , $\sigma_{ad}^2$ , $\sigma_{dd}^2$ , $\sigma_{d}^2$ turned to Symbol. I had to manually change its family to "Times New Roman" in ppt to ensure normal display.
ggplot2to draw the picture, the label contains the Greek letter"family = "Times New Roman". However, after I exported, the family ofMy code:
sessionInfo()