簡體   English   中英

使用plotly在ggplot中更改軸標題位置

[英]Change axis title position in ggplot using plotly

ggplot圖上使用ggplotlyggplotly問題。 它基本上與此處完全相同。 但是,如果繪圖沒有刻面,則提供的解決方案不起作用,因為在這種情況下不應存在應該更改的對象gp[['x']][['layout']][['annotations']] (不幸的是,我沒有足夠的聲譽來發表評論,因此我不得不提出這個問題作為一個新問題。)結果,我找不到如何在非刻面情節中調整y軸標題位置。 這是另一個問題的工作示例

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))

(注意:在這個具體的例子中,軸標題和軸標簽之間沒有重疊,但是我想指出軸標題重新定位不能基於相同的例子。)

這是一個解決您的問題的技巧:

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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM