如何在plotly的更新版本中设置布局?
How to set the layout in the updated version of plotly?
我正在尝试使用新版 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)
布局命令不起作用,如果有人知道为什么以及我应该怎么做,我将不胜感激!
谢谢!
老实说,我对整个plotly包不是很了解。我不能告诉你为什么它不起作用(我只是不知道),但我更改了你的代码并得到了输出!
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"]])
a <- 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)'))
b <- 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 = a,
yaxis = b)
很抱歉我无法为您提供解释,但希望对您有所帮助!
您可以尝试在 plot_ly
和 layout
之间添加 %>%
。
这是上述 %>%
管道的一个简单示例
p <- plot_ly(
type = "scatter",
data = vep_wes_aff_rare_summary,
x = ~n,
y = ~mean_af
)%>%
layout(
title = 'Styled Scatter',
yaxis = list(zeroline = FALSE),
xaxis = list(zeroline = FALSE)
)
我正在尝试使用新版 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)
布局命令不起作用,如果有人知道为什么以及我应该怎么做,我将不胜感激!
谢谢!
老实说,我对整个plotly包不是很了解。我不能告诉你为什么它不起作用(我只是不知道),但我更改了你的代码并得到了输出!
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"]])
a <- 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)'))
b <- 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 = a,
yaxis = b)
很抱歉我无法为您提供解释,但希望对您有所帮助!
您可以尝试在 plot_ly
和 layout
之间添加 %>%
。
这是上述 %>%
管道的一个简单示例
p <- plot_ly(
type = "scatter",
data = vep_wes_aff_rare_summary,
x = ~n,
y = ~mean_af
)%>%
layout(
title = 'Styled Scatter',
yaxis = list(zeroline = FALSE),
xaxis = list(zeroline = FALSE)
)