0

这就是我的代码现在的样子:

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(11000, 16000, 21000, 27000, 33000, 37000, 43000, 54000, 68000, 94000, 128000, 170000, 213000, 258000, 307000, 348000, 385000)

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)

但是 y 轴上的每个刻度都显示在 0 标记中。有没有办法改变刻度分布的比例?图形本身看起来不错。谢谢!

4

1 回答 1

0

您需要:

  • 指定autotick = TRUE
  • 或手动指定tickvalticktext如下所示:

    b <- list(title = "Years",
          showline = TRUE,
          showgrid = FALSE,
          showticklabels = TRUE,
          linecolor = 'black',
          linewidth = 1,
          tickval = amt,
          ticktext = amt,
          ticks = 'outside',
          tickcolor = 'black',
          tickwidth = 2,
          ticklen = 5,
          tickfont = list(family = 'Cambria',
                          size = 10,
                          color = 'rgb(82, 82, 82)'))
    
于 2016-10-27T18:25:22.257 回答