ggplot2でタイトルとx軸y軸の設定
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン次のリビジョン両方とも次のリビジョン | ||
ggplot2でタイトルとx軸y軸の設定 [2018/08/12] – [グラフタイトルをグラフ上部中央に記載する] adash333 | ggplot2でタイトルとx軸y軸の設定 [2019/10/13] – [Rでグラフを描くための初心者向けのおすすめの本] adash333 | ||
---|---|---|---|
行 9: | 行 9: | ||
===== 開発環境 ===== | ===== 開発環境 ===== | ||
- | RStudio Cloudのconsole画面(画面左下)で、install.package(" | + | RStudio Cloudのconsole画面(画面左下)で、install.packages(" |
参考:http:// | 参考:http:// | ||
行 16: | 行 16: | ||
+ | ===== x軸の値を変更する ===== | ||
+ | ==== x軸の値が離散値(?)の場合 ==== | ||
+ | |||
+ | < | ||
+ | scale_x_discrete(“Time”, | ||
+ | </ | ||
+ | のように用いる。 | ||
+ | |||
+ | 例) | ||
+ | < | ||
+ | b <- b + | ||
+ | scale_x_discrete(" | ||
+ | theme(plot.title = element_text(hjust = 0.5), text = element_text(size=20)) | ||
+ | </ | ||
+ | |||
+ | https:// | ||
+ | ==== x軸の値が連続値の場合 ==== | ||
+ | |||
+ | |||
+ | < | ||
+ | coord_cartesian(ylim = c(0,25)) + | ||
+ | scale_x_continuous(breaks = seq(0, | ||
+ | </ | ||
+ | のような感じで用いる。 | ||
+ | |||
+ | 例) | ||
+ | < | ||
+ | b <- b + coord_cartesian(ylim = c(0,25)) + | ||
+ | scale_x_continuous(breaks = seq(0, | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== ggplot2でグラフのタイトルを真ん中に ===== | ||
+ | |||
+ | < | ||
+ | b <- b + ggtitle(“New Title”) | ||
+ | b <- b + theme(plot.title = element_text(hjust=0.5)) | ||
+ | b <- b + theme(plot.title = element_text(size = 20), | ||
+ | axis.title.x = element_text(size= 20), | ||
+ | axis.title.y = element_text(size= 20), | ||
+ | axis.text.x = element_text(size= 20), | ||
+ | axis.text.y = element_text(size= 20)) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== グループによって少しだけx軸方向にずらす ===== | ||
+ | |||
+ | |||
+ | < | ||
+ | pd <- position_dodge(0.1) | ||
+ | |||
+ | ggplot(tgc, aes(x=dose, y=len, colour=supp)) + geom_errorbar(aes(ymin=len-se, | ||
+ | </ | ||
+ | |||
+ | のように使う。 | ||
+ | |||
+ | http:// | ||
+ | |||
+ | ===== リンク ===== | ||
+ | |||
+ | https:// | ||
===== Rでグラフを描くための初心者向けのおすすめの本 ===== | ===== Rでグラフを描くための初心者向けのおすすめの本 ===== | ||
行 25: | 行 86: | ||
<iframe style=" | <iframe style=" | ||
</ | </ | ||
+ | |||
+ | 上記の本でggplot2に慣れたら、以下の本でデータ整理について学んでみるのがお勧めです。 | ||
+ | |||
+ | < | ||
+ | <iframe style=" | ||
+ | </ | ||
+ | |||
+ | ===== リンク ===== | ||
+ | 目次:[[初めての医療統計: | ||
+ | |||
+ | |||
+ |
ggplot2でタイトルとx軸y軸の設定.txt · 最終更新: 2020/08/12 by adash333