2017-11-10 18 views
0

ggplotグラフにggplotlyを使用すると問題が発生します。基本的にはhereと全く同じ問題です。ただし、プロットがファセット化されていない場合は、この場合はオブジェクトgp[['x']][['layout']][['annotations']]を変更する必要があるため、提案されたソリューションは機能しません。 (残念ながら、私はコメントする評判が十分ではないので、新しい質問として問題を提起する必要があります。) 結果として、非面取りプロットのy軸タイトル位置の調整方法が見つかりません。これはthe other questionplglyを使ってggplotの軸のタイトル位置を変更する

library(gapminder) 
library(plotly) 
p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) + 
    geom_point() + 
    scale_x_log10() 
p <- p + aes(color = continent) + facet_wrap(~year) 
gp <- ggplotly(p) 
gp[['x']][['layout']][['annotations']][[2]][['x']] <- -0.1 
gp %>% layout(margin = list(l = 75)) 

から作業例であり、これは非稼働の相手である:

p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) + 
    geom_point() + 
    scale_x_log10() 
gp <- ggplotly(p) 
gp[['x']][['layout']][['annotations']][[2]][['x']] <- -0.1 
gp %>% layout(margin = list(l = 75)) 

(注:この特定の例では、軸のタイトルと軸ラベル間の重複がない、しかし、私は、再配置軸のタイトルが同じ例に基づいて動作しないという事実を指摘したかった)ここで

答えて

1

はあなたの問題を解決トリックです:。

library(gapminder) 
library(plotly) 

gapminder$grp <- "" 
p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) + 
    geom_point() + 
    scale_x_log10() + 
    facet_wrap(~grp) 
gp <- ggplotly(p) 
gp[['x']][['layout']][['annotations']][[2]][['x']] <- -0.1 
gp %>% layout(margin = list(l = 75)) 
関連する問題