LoginSignup
37
48

More than 5 years have passed since last update.

ggplot2で論文用の図を作るときに使いたいオプション(点のshape、色、軸の文字の大きさ、色、エラーバー、背景)

Posted at

この記事の目的

さっき論文用の図を作っていて、「これどうやるんだっけ?」となったオプションのメモです。
順次追記する予定です。
間違いなどありましたら、コメント欄でご指摘ください。

背景を消す

g + theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.background = element_blank()
    )

軸の色を変える

g + theme(axis.line=element_line(colour = "black"),
          axis.ticks=element_line(colour = "black")
    )

軸のタイトルとラベルの文字サイズを変える

出典: r - Change size of axes title and labels in ggplot2 - Stack Overflow

g+theme(axis.text=element_text(size=12),
        axis.title=element_text(size=14,face="bold"))

エラーバーつきのプロットの作成

出典: Cookbook for R » Plotting means and error bars (ggplot2)

dfcであらかじめseの値を持っておいた上で)

ggplot(dfc, aes(x=dose, y=len, colour=supp)) + 
    geom_errorbar(aes(ymin=len-se, ymax=len+se), width=.1) +
    geom_line() +
    geom_point()

エラーバーのtick(?)の幅はwidthで設定できる。

点の形(shape)を手動で設定する

ggplot(dat, aes(x=xvar, y=yvar, shape=cond)) + geom_point() +
    scale_shape_manual(values=c(1,2)) 

出典: Cookbook for R » Scatterplots (ggplot2)

点の色を設定する

g + geom_point(colour="white")
g + geom_point(fill="white")

ただし、colourfillで色を設定できるshapeが違う。fillで色を設定しようと思ったら、21, 22, 23, 24, 25だけ。
出典: geom_point - 浅井拓也 研究室用ページ

y軸の範囲

scale_y_continuous(expand = c(0,0), limits=c(0,1.1* max(dt2[,sec] + dt2[,sd]) ))
37
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
48