ggplot
に基づいた の新しいテーマを作成したいと思いますtheme_bw()
。
次の手順が必要だと思います (疑似コード)。
- theme_bw() のコピーを作成します:
theme_new() <- theme_bw()
- コピーを変更します:
theme_update(axis.title.x = theme_text(family = base_family, size = base_size, vjust = 0.5))
これを実装する方法に関するアドバイスをいただければ幸いです。
編集:@Andrie、あなたの回答を自分のニーズに合わせて修正しました:
theme_new <- theme_set(theme_bw())
theme_new <- theme_update(axis.title.x = theme_text(family = base_family, size = base_size, vjust = 0.5))
ただし、次のエラーが発生します。
ggplot(mtcars, aes(factor(cyl))) + geom_bar()
match(gparname, names(gpars)) でエラーが発生しました: オブジェクト 'base_size' が見つかりません
編集:2017 年 10 月 31 日、@Andrie による回答は問題なく機能します。R バージョン 3.4.1、ggplot2_2.2.1
ベストアンサー1
コードを動作させるには、いくつかの小さな変更が必要です(主に括弧を削除し、適切な場所に括弧を追加します)
theme_new <- theme_set(theme_bw())
theme_new <- theme_update(
panel.background = element_rect(fill="lightblue"))
ggplot(mtcars, aes(factor(cyl))) + geom_bar()
参照: