首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在RStudio中不推荐使用绘图图表的问题

在RStudio中不推荐使用绘图图表的问题
EN

Stack Overflow用户
提问于 2019-04-20 02:32:48
回答 1查看 525关注 0票数 0

我正在尝试熟悉plotly的功能和语法,并尝试了几个用来组成和呈现数据图的脚本。但是,在使用RStudio生成绘图输出时,我收到以下错误:“警告消息:现在不推荐在布局()中指定宽度/高度。请在plot_ly()或ggplotly()中指定。”

在RStudio控制台中,输出的图像看起来杂乱无章,无法解释,我尝试了一些更改,比如将plotly对象的宽度和高度设置为空,等等。

以下是我遇到此问题时使用的示例脚本之一:

代码语言:javascript
复制
library(plotly)
trace1 <- list(
  x = c("Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12", "Jan-12", "Feb-13", "Mar-13", "Apr-13", "May-13", "Jun-13", "Jul-13"), 
  y = c(65, 77, 112, 279, 172, 133, 152, 106, 79, 225, 99, 150), 
  hoverinfo = "x+y+name", 
  line = list(
    color = "#5BC075", 
    width = "3"
  ), 
  mode = "lines", 
  name = "Median deal size", 
  type = "scatter", 
  uid = "a8e83b", 
  xsrc = "jackluo:508:b357d2", 
  ysrc = "jackluo:508:d19900"
)
trace2 <- list(
  x = c("Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12", "Jan-12", "Feb-13", "Mar-13", "Apr-13", "May-13", "Jun-13", "Jul-13"), 
  y = c(116, 125, 126, 125, 244, 136, 80, 82, 89, 82, 95, 107), 
  hoverinfo = "x+y+name", 
  line = list(
    color = "#CC6E55", 
    width = "3"
  ), 
  mode = "lines", 
  name = "Number of deals", 
  type = "scatter", 
  uid = "2be33b", 
  xsrc = "jackluo:508:b357d2", 
  ysrc = "jackluo:508:5d533d"
)
data <- list(trace1, trace2)
layout <- list(
  autosize = TRUE, 
  font = list(
    family = "Overpass", 
    size = 12
  ), 
  height = 720, 
  legend = list(
    x = 0, 
    y = -0.1, 
    bgcolor = "rgba(255, 255, 255, 0)", 
    orientation = "h"
  ), 
  margin = list(
    r = 40, 
    t = 40, 
    b = 40, 
    l = 40, 
    pad = 2
  ), 
  title = "", 
  width = 1280, 
  xaxis = list(
    autorange = TRUE, 
    nticks = 12, 
    range = c(0, 11), 
    rangemode = "tozero", 
    type = "category"
  ), 
  yaxis = list(
    autorange = TRUE, 
    range = c(0, 293.6842105263158), 
    rangemode = "tozero", 
    type = "linear"
  )
)
p <- plot_ly()
p <- add_trace(p, x=trace1$x, y=trace1$y, hoverinfo=trace1$hoverinfo, line=trace1$line, mode=trace1$mode, name=trace1$name, type=trace1$type, uid=trace1$uid, xsrc=trace1$xsrc, ysrc=trace1$ysrc)
p <- add_trace(p, x=trace2$x, y=trace2$y, hoverinfo=trace2$hoverinfo, line=trace2$line, mode=trace2$mode, name=trace2$name, type=trace2$type, uid=trace2$uid, xsrc=trace2$xsrc, ysrc=trace2$ysrc)
p <- layout(p, autosize=layout$autosize, font=layout$font, height=layout$height, legend=layout$legend, margin=layout$margin, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis)
p$x$layout$width <- NULL
p$x$layout$height <- NULL
p$width <- NULL
p$height <- NULL
p

任何帮助解决这个问题,以便图表是正确的比例和可读性将非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2019-04-20 02:50:51

X轴看起来是一个字符,而不是日期,所以轴是按字母顺序而不是按时间顺序排序的。我会尝试将x值设为日期。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55766248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档