如何在曲线上改变轴特征?(How to change axis features in plotly?)
我在剧情中有以下栏,我想:
从轴标签获取x轴标题,使它们不重叠 使Y轴标签更大 将条形值带到条形的顶部
我的代码是:
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 = " "))感谢您的意见 :)
I have the following bar in plotly and I want to :
get the x-axis title away from the axis label so they dont overlap make the Y-axis labels bigger bring the bar values to the top of barsMy code is :
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 = " "))Thanks for your comments :)
最满意答案
问题1:使x轴标题远离轴标签,使它们不重叠 在layout使用margin = list(b=100, l=100)设置适当的边距可以解决此问题。 问题2:使Y轴标签更大。 在layout使用xaxis = list(titlefont=list(size=30)) 问题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)))
Question 1: get the x-axis title away from the axis label so they dont overlap This problem can be solved setting proper margins with margin = list(b=100, l=100) in layout. Question 2: make the Y-axis labels bigger. Use xaxis = list(titlefont=list(size=30)) in layout Question 3: bring the bar values to the top of bars. Use add_text with 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)))更多推荐
发布评论