00.初めての医療統計rとezr:08.ggplot2でグラフの体裁を調整
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
00.初めての医療統計rとezr:08.ggplot2でグラフの体裁を調整 [2019/10/21] – [タイトルとx軸y軸] adash333 | 00.初めての医療統計rとezr:08.ggplot2でグラフの体裁を調整 [2022/02/22] (現在) – [タイトルとx軸y軸] adash333 | ||
---|---|---|---|
行 1: | 行 1: | ||
====== 08.ggplot2でグラフの体裁を調整 ====== | ====== 08.ggplot2でグラフの体裁を調整 ====== | ||
+ | [[00.初めての医療統計rとezr: | ||
+ | |||
+ | |||
前回の[[00.初めての医療統計rとezr: | 前回の[[00.初めての医療統計rとezr: | ||
+ | |||
+ | ===== ggplot2で論文用の白黒のグラフをかく ===== | ||
+ | |||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== エスキス ===== | ||
+ | [[https:// | ||
+ | |||
+ | < | ||
+ | # RStudioの場合は、Console画面で、以下を入力 | ||
+ | install.packages(" | ||
+ | # remotes:: | ||
+ | |||
+ | # esquisse:: | ||
+ | |||
+ | # Webブラウザで開きたい場合 | ||
+ | esquisse:: | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | csvファイルは、UTF-8でエンコードしておく必要がありそう。 | ||
+ | |||
+ | pptx出力する場合は、 | ||
+ | < | ||
+ | Packages ' | ||
+ | </ | ||
+ | だそうです。 | ||
+ | < | ||
+ | install.packages(" | ||
+ | install.packages(" | ||
+ | </ | ||
+ | すれば、パワーポイントファイル(pptx)として出力することもできます。どちらも非常に便利。 | ||
+ | |||
+ | |||
+ | |||
+ | エスキスの使い方(英語) | ||
+ | https:// | ||
+ | |||
+ | |||
+ | |||
+ | https:// | ||
+ | @taro_9674 | ||
+ | 2019年07月25日に投稿 | ||
+ | 【R言語】もうggplot2の操作も怖くない!esquisseパッケージの効力が絶大だった件 | ||
+ | |||
+ | https:// | ||
+ | R言語: | ||
+ | Osamu_Machida | ||
+ | 2019/02/23 13:07 | ||
+ | |||
+ | https:// | ||
+ | Rのおすすめパッケージ2019年版 | ||
+ | |||
+ | |||
===== グラフ全体の大きさと解像度 ===== | ===== グラフ全体の大きさと解像度 ===== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 背景を消す | ||
+ | < | ||
+ | g + theme(panel.grid.major = element_blank(), | ||
+ | panel.grid.minor = element_blank(), | ||
+ | panel.background = element_blank() | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | |||
===== タイトルとx軸y軸 ===== | ===== タイトルとx軸y軸 ===== | ||
- | タイトルがデフォルトだと左寄り。中央寄せにしたいときはthemeにelement_text(hjust = 0.5)を指定します。 | + | タイトルはデフォルトだと左寄り。中央寄せにしたいときはthemeにelement_text(hjust = 0.5)を指定します。 |
< | < | ||
行 16: | 行 89: | ||
</ | </ | ||
+ | 軸のタイトルとラベルの文字サイズを変える | ||
+ | < | ||
+ | g+theme(axis.text=element_text(size=12), | ||
+ | axis.title=element_text(size=14, | ||
+ | </ | ||
+ | 軸の表示範囲を設定 | ||
< | < | ||
scale_x_continuous(breaks = seq(10, 100, by = 10)) | scale_x_continuous(breaks = seq(10, 100, by = 10)) | ||
scale_x_log10(limit = c(0.1 , 10)) | scale_x_log10(limit = c(0.1 , 10)) | ||
scale_y_log10(breaks = c(1, 5, 10)* 1000) | scale_y_log10(breaks = c(1, 5, 10)* 1000) | ||
+ | </ | ||
+ | |||
+ | x軸の表示の順番を変える(factorの場合) | ||
+ | < | ||
+ | scale_x_discrete(limit=c(' | ||
+ | </ | ||
+ | |||
+ | x軸の表示の値を変える(factorの場合) | ||
+ | < | ||
+ | scale_x_discrete(" | ||
+ | </ | ||
+ | |||
+ | 値を変えて、同時に順序も変える(factor) | ||
+ | < | ||
+ | ggplot(summary_d, | ||
+ | geom_line() + | ||
+ | geom_point() + | ||
+ | scale_x_discrete( | ||
+ | limit = c(" | ||
+ | breaks = c(" | ||
+ | labels = c(" | ||
+ | ) + | ||
+ | scale_shape_manual(values=c(1, | ||
+ | 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() | ||
</ | </ | ||
行 56: | 行 161: | ||
2014年9月8日月曜日 | 2014年9月8日月曜日 | ||
ggplot2で作図4:デザイン | ggplot2で作図4:デザイン | ||
+ | |||
+ | https:// | ||
+ | @yuifu | ||
+ | 2015年03月10日に投稿 | ||
+ | ggplot2で論文用の図を作るときに使いたいオプション(点のshape、色、軸の文字の大きさ、色、エラーバー、背景) | ||
+ | |||
+ | http:// | ||
+ | 2016-10-08 | ||
+ | ggplot2を使って、軸を制御する-2 | ||
+ | |||
+ | |||
+ | |||
+ | http:// | ||
+ | 2016-10-24 | ||
+ | ggplot2を使って、軸を制御する-4 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
行 98: | 行 224: | ||
2019年5月6日2019年5月22日 | 2019年5月6日2019年5月22日 | ||
+ | |||
+ | ===== 対話的に ===== | ||
+ | |||
+ | https:// | ||
+ | ggplot2 をもっとカンタンに plotly 化する | ||
+ | 2019-3-22 by Atusy | ||
00.初めての医療統計rとezr/08.ggplot2でグラフの体裁を調整.1571668828.txt.gz · 最終更新: 2019/10/21 by adash333