2017-09-13 9 views
3

私はplotlyに次のバーを持っていると私がしたい:彼らは プロットで軸のフィーチャを変更するにはどうすればよいですか?

  • と重なっていけないので

    1. は離れ軸ラベルからのx軸のタイトルを取得するY軸のラベルを大きくする
    2. をもたらしますバー

    の先頭にバー値enter image description here

    私のコードは次のとおりです。

    library(plotly) 
    plot_ly(x = c('100-200','200-400', '400-600','600-800','800- 1000'), 
    y = c(12261,29637,17469,11233,17043),   
    name = "dd", 
    type = "bar", 
    xaxis = list(title ="tr"), 
    yaxis = list(title = "cc") ,             
    text = c(12261,29637,17469,11233,17043),textposition = 'auto') %>% 
    layout(
    xaxis = list(tickangle=15, title = " "), 
    yaxis = list(title = " ")) 
    

    あなたのグラフは、現時点では与えられたコードと全く再現できないので、私は不必要な仮定をしたなら、私が知っていることをあなたのコメント:)

  • 答えて

    2

    質問1:彼らはこの問題はlayoutmargin = list(b=100, l=100)との適切なマージンを設定し解決することができます
    重なってはいけないので、離れた軸ラベルからのx軸のタイトルを取得します。

    質問2:Y軸のラベルを大きくします。
    xaxis = list(titlefont=list(size=30))layout

    で使用する質問3:棒の値を棒の最上部に移動します。あなたの包括的な答えをtextposition = 'top'

    library(plotly) 
    
    x <- c('100-200','200-400', '400-600','600-800','800-1000') 
    y <- c(12261,29637,17469,11233,17043) 
    labs <- c(12261,29637,17469,11233,17043) 
    
    plot_ly(x = x, y = y,   
    name = "dd", 
    type = "bar", 
    xaxis = list(title ="tr"), 
    yaxis = list(title = "cc")) %>% 
    add_text(x=x, y=y, text=labs, hoverinfo='none', textposition = 'top', showlegend = FALSE, 
         textfont=list(size=20, color="black")) %>% 
    layout(margin = list(b=100, l=100), 
    xaxis = list(tickangle=15, title = "Lenght of exon", titlefont=list(size=30)), 
    yaxis = list(title = "Number of genes", titlefont=list(size=30))) 
    

    enter image description here

    +0

    感謝しています。本当にうまくいった:) – Behmah

    +0

    お知りになりましたが、どうやったらそれを受け入れるのですか? – Behmah

    +0

    私はそれを心配しないで得​​た – Behmah

    2

    注意していただきありがとうございます。

    TLDR:質問に記載されているすべての変更を希望する場合は、一番下を見てください。

    tickangleを少し使ってみることをお勧めします。以下を試してください。 yaxisにはinsidetextfonttickfontの使用に注意してください。

    library(plotly) 
    x = c('100-200','200-400', '400-600','600-800','800- 1000') 
    y = c(12261,29637,17469,11233,17043) 
    plot_ly(
        x = x, y = y, type = "bar", text = y, textposition = 'auto', 
        insidetextfont = list(color = 'white') 
    ) %>% layout(
        xaxis = list(title = "Length of exon"), 
        yaxis = list(title = "Number of genes", tickfont = list(size = 15)) 
    ) 
    

    enter image description here

    あなたはラベルを作りたい場合は代わりにtextposition = 'auto'textposition = 'outside'を使用し、その後、バーの外側に位置し、デフォルトの黒の色のinsidetextfontを取り除きます。それはy軸の範囲を乱してしまうかもしれません。手間のかかる範囲を手動で定義する必要があります。

    plot_ly(
        x = x, y = y, type = "bar", text = y, textposition = 'outside' 
    ) %>% layout(
        xaxis = list(title = "Length of exon"), 
        yaxis = list(
        title = "Number of genes", tickfont = list(size = 15), 
        range = c(0, max(y) + 2000) 
    ) 
    ) 
    

    これは私たちにenter image description hereを与えます。

    tickangleはお勧めできませんが、必要がある場合は、marginlayoutに使用してください。

    plot_ly(
        x = x, y = y, type = "bar", text = y, textposition = 'outside' 
    ) %>% layout(
        xaxis = list(title = "Length of exon", tickangle = 15), 
        yaxis = list(
        title = "Number of genes", tickfont = list(size = 15), 
        range = c(0, max(y) + 2000) 
    ), margin = list(b=100) 
    ) 
    

    enter image description here

    この情報がお役に立てば幸いです。

    +0

    おかげ飴屋と
    使用add_text :) – Behmah

    +0

    嬉しいそれが助けました。それがあなたを助けたと思えば、答えを受け入れることを検討してください。 – Ameya

    関連する問題