====== 08.ggplot2でグラフの体裁を調整 ====== [[00.初めての医療統計rとezr:index.html|初めての医療統計RとEZR]] 前回の[[00.初めての医療統計rとezr:07.colaboratoryで箱ひげ図と蜂群図|07.Google ColaboratoryでRで箱ひげ図と蜂群図(ほうぐんず)]] ===== ggplot2で論文用の白黒のグラフをかく ===== [[https://i-doctor.sakura.ne.jp/dokuwiki/doku.php/ggplot2%E3%81%A7%E8%AB%96%E6%96%87%E7%94%A8%E3%81%AE%E7%99%BD%E9%BB%92%E6%8A%98%E3%82%8C%E7%B7%9A%E3%82%B0%E3%83%A9%E3%83%95|ggplot2で論文用の白黒折れ線グラフ]] ===== エスキス ===== [[https://dreamrs.github.io/esquisse/index.html|esquisseエスキス]] # RStudioの場合は、Console画面で、以下を入力 install.packages("esquisse") # remotes::install_github("dreamRs/esquisse") # esquisse::esquisser(iris) # Webブラウザで開きたい場合 esquisse::esquisser(viewer = "browser") {{:00.初めての医療統計rとezr:pasted:20200506-001548.png}} {{:00.初めての医療統計rとezr:pasted:20200506-001836.png}} csvファイルは、UTF-8でエンコードしておく必要がありそう。 pptx出力する場合は、 Packages 'officer' and 'rvg' are required to use this functionality. だそうです。 install.packages("officer") install.packages("rvg") すれば、パワーポイントファイル(pptx)として出力することもできます。どちらも非常に便利。 エスキスの使い方(英語) https://dreamrs.github.io/esquisse/articles/get-started.html https://qiita.com/taro_9674/items/55dc92d30ba569465ca9 @taro_9674 2019年07月25日に投稿 【R言語】もうggplot2の操作も怖くない!esquisseパッケージの効力が絶大だった件 https://note.com/tqwst408/n/n82d56c69a18e R言語:ggplotのGUIをまとめてみる Osamu_Machida 2019/02/23 13:07 https://www.marketechlabo.com/r-best-packages/ Rのおすすめパッケージ2019年版 ===== グラフ全体の大きさと解像度 ===== 背景を消す g + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank() ) ===== タイトルとx軸y軸 ===== タイトルはデフォルトだと左寄り。中央寄せにしたいときはthemeにelement_text(hjust = 0.5)を指定します。 ggplot() + ggtitle("Use theme(plot.title = element_text(hjust = 0.5)) to center") + theme(plot.title = element_text(hjust = 0.5)) 軸のタイトルとラベルの文字サイズを変える g+theme(axis.text=element_text(size=12), axis.title=element_text(size=14,face="bold")) 軸の表示範囲を設定 scale_x_continuous(breaks = seq(10, 100, by = 10)) scale_x_log10(limit = c(0.1 , 10)) scale_y_log10(breaks = c(1, 5, 10)* 1000) x軸の表示の順番を変える(factorの場合) scale_x_discrete(limit=c('virginica', 'setosa', 'versicolor')) x軸の表示の値を変える(factorの場合) scale_x_discrete("Cut Type", labels = c("Fair" = "F","Good" = "G", "Very Good" = "VG","Premium" = "P","Ideal" = "I")) 値を変えて、同時に順序も変える(factor) ggplot(summary_d, aes(x = time, y = temp_mean, group = 1)) + geom_line() + geom_point() + scale_x_discrete( limit = c("before", "a0sec","a30sec","a60sec","a180sec"), breaks = c("before", "a0sec","a30sec","a60sec","a180sec"), labels = c("before", "0sec","30sec","60sec","180sec") ) + scale_shape_manual(values=c(1,15)) + scale_y_continuous(limits = c(20, 30)) + geom_errorbar(aes(ymax = temp_mean + temp_sd, ymin = temp_mean - temp_sd), width = 0.1) + theme_classic() 値を変えずに座標軸を変える scale_* coord_* coord_cartesian(ylim = c(800, 12000)) labs(title = "Diamonds", x = "Size(carat)", y = "Price(USD)") 使用する関数 *labs() *xlab() *ylab() *ggtitle() http://motw.mods.jp/R/ggplot_labs.html ggplotでの軸ラベル, タイトルの扱い方 https://notchained.hatenablog.com/entry/2016/10/15/134938 2016-10-15 ggplot2 2.2.0 を使ってみる [[http://i-doctor.sakura.ne.jp/dokuwiki/doku.php/ggplot2%E3%81%A7%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB%E3%81%A8x%E8%BB%B8y%E8%BB%B8%E3%81%AE%E8%A8%AD%E5%AE%9A|ggplot2でタイトルとx軸y軸の設定]] http://mukkujohn.hatenablog.com/entry/2016/10/11/220722 2016-10-11 ggplot2を使って、軸を制御する-3 http://yutakahogeta.blogspot.com/2014/09/ggplot2_8.html?m=1 2014年9月8日月曜日 ggplot2で作図4:デザイン https://qiita.com/yuifu/items/83103d03aef2dba95465 @yuifu 2015年03月10日に投稿 ggplot2で論文用の図を作るときに使いたいオプション(点のshape、色、軸の文字の大きさ、色、エラーバー、背景) http://mukkujohn.hatenablog.com/entry/2016/10/08/155023 2016-10-08 ggplot2を使って、軸を制御する-2 http://mukkujohn.hatenablog.com/entry/2016/10/24/232525 2016-10-24 ggplot2を使って、軸を制御する-4 ===== ggplot2でグラフの体裁を整える関連のリンク ===== https://heavywatal.github.io/slides/nagoya2018/2-ggplot.html http://nfunao.web.fc2.com/files/R-ggplot2.pdf ggplot2 パッケージの入門スライド ===== ggplot2で白黒グラフ ===== https://qiita.com/yuifu/items/83103d03aef2dba95465 @yuifu 2015年03月10日に投稿 ggplot2で論文用の図を作るときに使いたいオプション(点のshape、色、軸の文字の大きさ、色、エラーバー、背景) http://datascience-blog.com/2019/05/06/post-50/ ggplot2: 棒グラフに置いたテキストがグラフの枠からはみ出る問題を解決したい (geom_blank) 2019年5月6日2019年5月22日 ===== 対話的に ===== https://blog.atusy.net/2019/03/22/ggplotly-asif-layer/ ggplot2 をもっとカンタンに plotly 化する 2019-3-22 by Atusy https://blog.atusy.net/2018/11/10/ggplot2-legend-pos-n-just/ ggplot2のレジェンド位置を調整 2018-11-10 by Atusy ===== リンク ===== 目次:[[00.初めての医療統計rとezr:index.html|初めての医療統計RとEZR]] 前:[[00.初めての医療統計rとezr:07.colaboratoryで箱ひげ図と蜂群図|07.Google ColaboratoryでRで箱ひげ図と蜂群図(ほうぐんず)]] 次: