ggdensity()
[in ggpubr ]desc_statby()
[in ggpubr ]ggtexttable()
[in ggpubr ]ggparagraph()
[in ggpubr ]ggarrange()
function [in ggpubr ]. # "Sepal.Length" #:::::::::::::::::::::::::::::::::::::: density.p <- ggdensity(iris, x = "Sepal.Length", fill = "Species", palette = "jco") # Sepal.Length #:::::::::::::::::::::::::::::::::::::: # stable <- desc_statby(iris, measure.var = "Sepal.Length", grps = "Species") stable <- stable[, c("Species", "length", "mean", "sd")] # , "medium orange" ( ) stable.p <- ggtexttable(stable, rows = NULL, theme = ttheme("mOrange")) # #:::::::::::::::::::::::::::::::::::::: text <- paste("iris data set gives the measurements in cm", "of the variables sepal length and width", "and petal length and width, respectively,", "for 50 flowers from each of 3 species of iris.", "The species are Iris setosa, versicolor, and virginica.", sep = " ") text.p <- ggparagraph(text = text, face = "italic", size = 11, color = "black") # ggarrange(density.p, stable.p, text.p, ncol = 1, nrow = 3, heights = c(1, 0.5, 0.3))
annotation_custom()
[in ggplot2 ]. Simplified format: annotation_custom(grob, xmin, xmax, ymin, ymax)
density.p + annotation_custom(ggplotGrob(stable.p), xmin = 5.5, ymin = 0.7, xmax = 8)
ggscatter()
[ ggpubr ] function .ggboxplot()
[ ggpubr ].ggplotGrob()
[ ggplot2 ].annotation_custom()
[ ggplot2 ] function . # ("Species") #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: sp <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width", color = "Species", palette = "jco", size = 3, alpha = 0.6) # x/y #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # x xbp <- ggboxplot(iris$Sepal.Length, width = 0.3, fill = "lightgray") + rotate() + theme_transparent() # ybp <- ggboxplot(iris$Sepal.Width, width = 0.3, fill = "lightgray") + theme_transparent() # # “grob” Grid xbp_grob <- ggplotGrob(xbp) ybp_grob <- ggplotGrob(ybp) # #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: xmin <- min(iris$Sepal.Length); xmax <- max(iris$Sepal.Length) ymin <- min(iris$Sepal.Width); ymax <- max(iris$Sepal.Width) yoffset <- (1/15)*ymax; xoffset <- (1/15)*xmax # xbp_grob sp + annotation_custom(grob = xbp_grob, xmin = xmin, xmax = xmax, ymin = ymin-yoffset, ymax = ymin+yoffset) + # ybp_grob annotation_custom(grob = ybp_grob, xmin = xmin-xoffset, xmax = xmin+xoffset, ymin = ymin, ymax = ymax)
readJPEG()
function [in the jpeg package] or the readPNG()
function [in the png package] depending on the format of the background image.install.packages(“png”)
command. # img.file <- system.file(file.path("images", "background-image.png"), package = "ggpubr") img <- png::readPNG(img.file)
background_image()
[in ggpubr ]. library(ggplot2) library(ggpubr) ggplot(iris, aes(Species, Sepal.Length))+ background_image(img)+ geom_boxplot(aes(fill = Species), color = "white")+ fill_palette("jco")
library(ggplot2) library(ggpubr) ggplot(iris, aes(Species, Sepal.Length))+ background_image(img)+ geom_boxplot(aes(fill = Species), color = "white", alpha = 0.5)+ fill_palette("jco")
mypngfile <- download.file("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/France_Flag_Map.svg/612px-France_Flag_Map.svg.png", destfile = "france.png", mode = 'wb') img <- png::readPNG('france.png') ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + background_image(img)+ geom_point(aes(color = Species), alpha = 0.6, size = 5)+ color_palette("jco")+ theme(legend.position = "top")
ggarrange()
function [in ggpubr ] provides a convenient solution to place several ggplot-s on several pages. After setting the nrow and ncol arguments, the ggarrange()
function automatically calculates the number of pages it takes to place all the graphs. It returns a list of ordered ggplot-s. multi.page <- ggarrange(bxp, dp, bp, sp, nrow = 1, ncol = 2)
multi.page[[1]] # 1 multi.page[[2]] # 2
ggexport()
function [in ggpubr ]: ggexport(multi.page, filename = "multi.page.ggplot2.pdf")
marrangeGrob()
function [in gridExtra ]. library(gridExtra) res <- marrangeGrob(list(bxp, dp, bp, sp), nrow = 1, ncol = 2) # pdf- ggexport(res, filename = "multi.page.ggplot2.pdf") # res
p1 <- ggarrange(sp, bp + font("x.text", size = 9), ncol = 1, nrow = 2) p2 <- ggarrange(density.p, stable.p, text.p, ncol = 1, nrow = 3, heights = c(1, 0.5, 0.3)) ggarrange(p1, p2, ncol = 2, nrow = 1)
ggexport()
[in ggpubr ]. plots <- ggboxplot(iris, x = "Species", y = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"), color = "Species", palette = "jco" ) plots[[1]] # plots[[2]] # ..
ggexport(plotlist = plots, filename = "test.pdf")
ggexport(plotlist = plots, filename = "test.pdf", nrow = 2, ncol = 1)
Source: https://habr.com/ru/post/339090/
All Articles