R言語による医療データ分析

R言語によるデータ分析のオンラインコースを中心に、さまざまなデータ分析について記載してあります。

061-062 ggplotのテーマ設定方法

まとめ一覧

 Theme 設定

  • 単純にグラフにtheme_XXX()を足すだけで、お手軽にテーマ設定ができます。
text_label_of_clarity <- c("含まれる",
                           "わずかにSI2","わずかにSI1",
                           "ほんのわずかにVS2","ほんのわずかにVS1",
                           "ごくごくわずかにVVS2","ごくごくわずかにVVS1",
                           "内部が無傷")


graph <- ggplot(diamonds) + 
  geom_histogram(aes(carat, fill = clarity)) +
  labs(title = "値段と重さと透明度の関係", x = "重さ(カラット)", y = "値段") +
  scale_fill_discrete(name = "透明度",
                       labels = text_label_of_clarity) 
graph

graph + theme_gray()

graph + theme_bw()

graph + theme_linedraw()

graph + theme_light()

graph + theme_dark()

graph + theme_minimal()

graph + theme_classic()

?theme
  • 色々なテーマを集めた、ggthemesパッケージというものがあります。
install.packages("ggthemes")

graph + ggthemes::theme_base()
graph + ggthemes::theme_calc()
graph + ggthemes::theme_economist() #Economist(雑誌)とにたテーマ
graph + ggthemes::theme_economist_white()
graph + ggthemes::theme_excel() #helpの説明分がひどい・・・「絶対につかわないで」
graph + ggthemes::theme_few()
graph + ggthemes::theme_fivethirtyeight()
graph + ggthemes::theme_gdocs()
graph + ggthemes::theme_stata()
graph + ggthemes::theme_wsj() #Wall Street Journalとにたテーマ

まとめ一覧