Analysis in R: “bluepRint” package for plotting various ggplot objects

RAnalytics
スポンサーリンク

This is an introduction to a package that allows you to easily plot multiple ggplot2 objects. It would be useful for routine repetitive output, as long as the plot area and plot style are specified.

Package version is 0.0.0.9000. Checked with R version 4.2.2.

スポンサーリンク

Install Package

Run the following command.

#Install Package
install.packages("devtools")
devtools::install_github("zaczap/bluepRint")

Example

See the command and package help for details.

#Loading the library
library("bluepRint")

###Creating Data#####
n <- 30
TestData <- data.frame(Group = sample(paste0("Group", 1:5), n, replace = TRUE),
                       Data1 = rnorm(n),
                       Data2 = rnorm(n) + rnorm(n) + rnorm(n),
                       Data3 = sample(0:1, n, replace = TRUE),
                       Data4 = sample(LETTERS[1:26], n, replace = TRUE))
#######

###Create ggplot2 object#####
#BoxPlot
BoxPlot <- qplot(data = TestData, x = Group, y = Data1, fill = Group, geom = "boxplot")
#ScatterPlot
PointPlot <- qplot(data = TestData, x = Data2, y = Data1, color = Group, geom = "point") +
  ggtitle("TEST")
#BarChart
BarPlot <- qplot(data = TestData, x = Data4, fill = Data4, geom = "bar") +
  guides(fill = "none")
#Split BarChart by Group
FacetBarPlot <- qplot(data = TestData, x = Data4, fill = Data4, geom = "bar") +
  facet_wrap(~Group, nrow = 1) + guides(fill = "none")
########

#Place graphs side by side:blueprint command
#Layout style:layout option;"line","square","left_feature"
#Assign A, B, C, D graph labels:label option
#2 plots side by side
blueprint(layout = "line", BoxPlot, PointPlot, label = TRUE)
#3 plots side by side
blueprint(layout = "line", BoxPlot, PointPlot, BarPlot, label = TRUE)
#2*2 plot
blueprint(layout = "square", BoxPlot, PointPlot, BarPlot, FacetBarPlot, label = TRUE)
#One large plot on the left, two plotted up and down on the right
blueprint(layout = "left_feature", BoxPlot, PointPlot, BarPlot, label = TRUE)

Output Example

・2 plots side by side

2line

・3 plots side by side

3line

・2*2 plot

square

・One large plot on the left, two plotted up and down on the right

left_feature

I hope this makes your analysis a little easier !!

Amazon audibleの登録の紹介

プライム会員限定で2024年7月22日まで3か月無料体験キャンペーン開催中です。無料体験後は月額1,500円で聞き放題です。なお、聞き放題対象外の本はAudible会員であれば非会員価格の30%引きで購入することが可能です。

Amazon audibleはプロのナレーターが朗読した本をアプリで聞くことができるサービスで、オフライン再生も可能です。通勤や作業のお供にAmazon audibleのご登録はいかがでしょうか。

・AmazonのAudible

https://amzn.to/3L4FI5o

Copied title and URL