gpt4 book ai didi

r - 如何更改绘图中的轴特征?

转载 作者:行者123 更新时间:2023-12-03 00:01:09 27 4
gpt4 key购买 nike

我有以下 plotly ,我想:

  1. 使 x 轴标题远离轴标签,这样它们就不会重叠
  2. 使 Y 轴标签更大
  3. 将条形值移至条形顶部

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

感谢您的评论:)

最佳答案

问题 1:使 x 轴标题远离轴标签,这样它们就不会重叠
这个问题可以通过在 layout 中设置适当的边距来解决 margin = list(b=100, l=100)

问题2:将Y轴标签调大。
布局中使用xaxis = list(titlefont=list(size=30))

问题 3:将条形值移至条形顶部。
add_texttextposition = '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

关于r - 如何更改绘图中的轴特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46189779/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com