ggplot2でタイトルとx軸y軸の設定

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
ggplot2でタイトルとx軸y軸の設定 [2018/08/12]
adash333 [グラフタイトルをグラフ上部中央に記載する]
ggplot2でタイトルとx軸y軸の設定 [2018/10/07] (現在)
ライン 9: ライン 9:
 ===== 開発環境 ===== ===== 開発環境 =====
  
-RStudio Cloudのconsole画面(画面左下)で、install.package("​tidyverse"​)を入力して、tidyverseパッケージをインストールした状態とします。+RStudio Cloudのconsole画面(画面左下)で、install.packages("​tidyverse"​)を入力して、tidyverseパッケージをインストールした状態とします。
  
 参考:http://​twosquirrel.mints.ne.jp/?​p=26918 参考:http://​twosquirrel.mints.ne.jp/?​p=26918
ライン 16: ライン 16:
  
  
 +===== x軸の値を変更する =====
  
  
 +==== x軸の値が離散値(?)の場合 ====
 +
 +<​code>​
 +scale_x_discrete(“Time”,​ labels = c(“1″=”first”,​ “2”=”second”,​ “3”=”third”)
 +</​code>​
 +のように用いる。
 +
 +例)
 +<​code>​
 +b <- b + 
 +  scale_x_discrete("​Time",​ labels = c("​Course1"​ = "​preop",​ "​Course2"​ = "one week", "​Course3"​ = "one month",​ "​Course4"​ = "three months"​)) +
 +  theme(plot.title = element_text(hjust = 0.5), text = element_text(size=20))
 +</​code>​
 +
 +https://​stackoverflow.com/​questions/​13297995/​changing-font-size-and-direction-of-axes-text-in-ggplot2
 +==== x軸の値が連続値の場合 ====
 +
 +
 +<​code>​
 +coord_cartesian(ylim = c(0,25)) + 
 +scale_x_continuous(breaks = seq(0,​25,​by=5),​labels=c(0,​5,​10,​15,​20,​25))
 +</​code>​
 +のような感じで用いる。
 +
 +例)
 +<​code>​
 +b <- b + coord_cartesian(ylim = c(0,25)) + 
 +scale_x_continuous(breaks = seq(0,​25,​by=5),​labels=c(0,​5,​10,​15,​20,​25))
 +</​code>​
 +
 +
 +===== ggplot2でグラフのタイトルを真ん中に =====
 +
 +<​code>​
 +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))
 +</​code>​
 +
 +
 +===== グループによって少しだけx軸方向にずらす =====
 +
 +
 +<​code>​
 +pd <- position_dodge(0.1)
 +
 +ggplot(tgc, aes(x=dose, y=len, colour=supp)) + geom_errorbar(aes(ymin=len-se,​ ymax=len+se),​ width=.1, position=pd) + geom_line(position=pd) + geom_point(position=pd)
 +</​code>​
 +
 +のように使う。
 +
 +http://​www.cookbook-r.com/​Graphs/​Plotting_means_and_error_bars_(ggplot2)/​
 +
 +===== リンク =====
 +
 +https://​heavywatal.github.io/​rstats/​ggplot2.html
  
 ===== Rでグラフを描くための初心者向けのおすすめの本 ===== ===== Rでグラフを描くための初心者向けのおすすめの本 =====
ライン 24: ライン 85:
 <​html>​ <​html>​
 <iframe style="​width:​120px;​height:​240px;"​ marginwidth="​0"​ marginheight="​0"​ scrolling="​no"​ frameborder="​0"​ src="//​rcm-fe.amazon-adsystem.com/​e/​cm?​lt1=_blank&​bc1=000000&​IS2=1&​bg1=FFFFFF&​fc1=000000&​lc1=0000FF&​t=twosquirrel-22&​language=ja_JP&​o=9&​p=8&​l=as4&​m=amazon&​f=ifr&​ref=as_ss_li_til&​asins=4873116538&​linkId=e9eb2c18d477e411419845d7c974fd7f"></​iframe>​ <iframe style="​width:​120px;​height:​240px;"​ marginwidth="​0"​ marginheight="​0"​ scrolling="​no"​ frameborder="​0"​ src="//​rcm-fe.amazon-adsystem.com/​e/​cm?​lt1=_blank&​bc1=000000&​IS2=1&​bg1=FFFFFF&​fc1=000000&​lc1=0000FF&​t=twosquirrel-22&​language=ja_JP&​o=9&​p=8&​l=as4&​m=amazon&​f=ifr&​ref=as_ss_li_til&​asins=4873116538&​linkId=e9eb2c18d477e411419845d7c974fd7f"></​iframe>​
 +</​html>​
 +
 +上記の本でggplot2に慣れたら、以下の本でデータ整理について学んでみるのがお勧めです。
 +
 +<​html>​
 +<iframe style="​width:​120px;​height:​240px;"​ marginwidth="​0"​ marginheight="​0"​ scrolling="​no"​ frameborder="​0"​ src="//​rcm-fe.amazon-adsystem.com/​e/​cm?​lt1=_blank&​bc1=000000&​IS2=1&​bg1=FFFFFF&​fc1=000000&​lc1=0000FF&​t=twosquirrel-22&​language=ja_JP&​o=9&​p=8&​l=as4&​m=amazon&​f=ifr&​ref=as_ss_li_til&​asins=487311814X&​linkId=0c89d7378632a8fa2f9442eb6408bf53"></​iframe>​
 </​html>​ </​html>​

ggplot2でタイトルとx軸y軸の設定.1534066316.txt.gz · 最終更新: 2018/10/07 (外部編集)