Rで解析:ggplot2の学習に便利かも「ggghost」パッケージ

Rの解析に役に立つ記事
スポンサーリンク

ggplot2はRの非常に有用なデータの表現パッケージです。そんなggplot2の学習に便利なパッケージの紹介です。ggplotオブジェクトの追加が理解しやすいので何かの参考になるかと思います。

パッケージバージョンは0.2.1。windows 7およびOS X 10.11.5のR version 3.3.1で確認しています。

スポンサーリンク

パッケージのインストール

下記コマンドを実行してください。

#パッケージのインストール
install.packages("ggghost")

実行コマンド

詳細はコマンド、パッケージのヘルプを確認してください。

#パッケージの読込
library("ggghost")

###データ例の作成#####
n <- 50
TestData <- data.frame("Group" = sample(paste0("Group", 1:3), n, replace = TRUE),
                          "Data1" = sample(rnorm(10), n, replace = TRUE))
########

#ggghost&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12398;&#20316;&#25104;:%g&lt;%&#12467;&#12510;&#12531;&#12489;
#ggghost&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12399;list class
TestPlot %g&lt;% ggplot(TestData, aes(x = Group, y = Data1, fill = Group))
TestPlot <- TestPlot +
  geom_boxplot() +
  labs(title = "Test ggplot") +
  geom_jitter(col = "red")

#&#12503;&#12525;&#12483;&#12488;
TestPlot
#ggghost&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12398;&#20869;&#23481;&#30906;&#35469;
#&#12467;&#12510;&#12531;&#12489;&#12391;&#34920;&#31034;&#12377;&#12427;&#12395;&#12399;combine = TRUE&#12434;&#36861;&#21152;
summary(TestPlot)
[[1]]
ggplot(TestData, aes(x = Group, y = Data1, fill = Group))
[[2]]
geom_boxplot()
[[3]]
labs(title = "Test ggplot")
[[4]]
geom_jitter(col = "red")

#ggplot&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12434;&#21066;&#38500;:-&#12467;&#12510;&#12531;&#12489;
#geom_jitter&#12434;&#21066;&#38500;
TestPlot - geom_jitter()
#title&#12434;&#21066;&#38500;
TestPlot - labs(title)

#&#12503;&#12525;&#12483;&#12488;&#20869;&#23481;&#12434;Gif&#12450;&#12491;&#12513;&#12391;&#20986;&#21147;:reanimate&#12467;&#12510;&#12531;&#12489;
reanimate(TestPlot, "TestPlot.gif")

出力例

・reanimateコマンド

ggghost

少しでも、あなたのウェブや実験の解析が楽になりますように!!

タイトルとURLをコピーしました