gpt4 book ai didi

r - 如何在plotly的更新版本中设置布局?

转载 作者:行者123 更新时间:2023-12-03 19:50:28 25 4
gpt4 key购买 nike

我正在尝试使用新版本的 plotly 绘制一个简单的图形,但我不断收到以下错误

Error in UseMethod("layout") : no applicable method for 'layout' applied to an object of class "character"



这是我的代码的样子:
library(plotly)
library(RColorBrewer)

year <- c(1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006)
amt <- c(11, 16, 21, 27, 33, 37, 43, 54, 68, 94, 128, 170, 213, 258, 307, 348, 385)

data <- data.frame(year, amt)

data$year <- factor(data$year, levels = data[["year"]])

xaxis <- list(title = "Years",
showline = TRUE,
showgrid = FALSE,
showticklabels = TRUE,
linecolor = 'black',
linewidth = 1,
autotick = FALSE,
ticks = 'outside',
tickcolor = 'black',
tickwidth = 2,
ticklen = 5,
tickfont = list(family = 'Cambria',
size = 10,
color = 'rgb(82, 82, 82)'))

yaxis <- list(title = "Years",
showline = TRUE,
showgrid = FALSE,
showticklabels = TRUE,
linecolor = 'black',
linewidth = 1,
autotick = FALSE,
ticks = 'outside',
tickcolor = 'black',
tickwidth = 2,
ticklen = 5,
tickfont = list(family = 'Cambria',
size = 10,
color = 'rgb(82, 82, 82)'))


plot_ly(data, x = ~year,
y = ~amt,
name= '',
type='scatter',
mode = 'lines+markers',
line = list(color = toRGB('#964f4d')),
marker = list(color = toRGB("#964f4d")))

layout(title = 'Pre-purchase financing poll',
xaxis = layout.xaxis,
yaxis = layout.yaxis)

布局命令不起作用,如果有人知道为什么以及我该怎么做,我将不胜感激!

谢谢!

最佳答案

您可以尝试添加 %>%之间plot_lylayout .

关于r - 如何在plotly的更新版本中设置布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40267907/

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