How to set the layout in the updated version of plotly?

plotly, r

Solution

You can try add `%>%` between `plot_ly` and `layout`.

Problem

I'm trying to plot a simple graphic using the new version of plotly but I keep getting the following error Error in UseMethod("layout") : no applicable method for 'layout' applied to an object of class "character" This is how my code looks like: ``` 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) ``` The layout command isn't working, if someone knows why and what should I do I would appreciate the help! Thank you!

Original source