2017-10-31 6 views
0

凡例の位置をグローバルオプションとして設定しようとしましたが、機能しませんでした。ggplot2で凡例の位置をグローバルオプションとして定義する方法

theme_set(theme_bw()) # Defining the global theme 
ggplot(data = iris, aes(x = Petal.Length, y=Sepal.Length, color = Species)) + 
    geom_point() 

enter image description here

私はそれが動作するよう凡例の位置は(プロットの下部になりたい:私は次のように、凡例の位置のみデフォルトとしてテーマを設定することができましたが、ありませんすべてのプロット、すなわち世界的に)。どうしたらいいですか?

乾杯

答えて

2

ちょうどあなたが次のように行うことができますggplot2のデフォルト設定を変更するには、あなたのtheme_set()


library(ggplot2) 

theme_set(theme_bw() + theme(legend.position = 'bottom')) # Defining the global theme 
ggplot(data = iris, aes(x = Petal.Length, y=Sepal.Length, color = Species)) + 
    geom_point() 

2

+ theme(legend.position = 'bottom')を追加するのに十分であるべきです:

new_theme <- theme_bw() %+replace% 
          theme(legend.position = "bottom") 

theme_set(new_theme) 

obs:これはどのargでも可能です。

関連する問題