trace order plotly R

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:36:52

The scatter trace has its y-axis set to y2 and yaxis2 in layout is overlaying y.

If you want to have the scatter trace in the background, reverse the y-axis assignment or set overlaying to y2 in yaxis.

library(plotly)

airquality_sept <- airquality[which(airquality$Month == 9),]
airquality_sept$Date <- as.Date(paste(airquality_sept$Month, 
                                      airquality_sept$Day, 1973, sep = "."), format = "%m.%d.%Y")

plot_ly(airquality_sept) %>%
  add_trace(x = ~Date, y = ~Temp, type = 'scatter', mode = 'lines', name = 'Temperature', yaxis = 'y2',
            line = list(color = '#45171D')
  ) %>%
  add_trace(x = ~Date, y = ~Wind, type = 'bar', name = 'Wind',
            marker = list(color = '#C9EFF9', opacity = 0.5)
  ) %>%
  layout(title = 'New York Wind and Temperature Measurements for September 1973',
         xaxis = list(title = ""),
         yaxis = list(side = 'left', title = 'Wind in mph', overlaying = "y2"),
         yaxis2 = list(side = 'right', title = 'Temperature in degrees F'))

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!