gpt4 book ai didi

r - 跟踪顺序 plotly R

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

我想弄清楚如何控制绘制的痕迹的顺序,即如何将痕迹带到前面和后面。

这里有一段简单的代码可以绘制两条轨迹。如何决定顺序?

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 = ~Wind, type = 'bar', name = 'Wind',
marker = list(color = '#C9EFF9')
) %>%
add_trace(x = ~Date, y = ~Temp, type = 'scatter', mode = 'lines', name = 'Temperature', yaxis = 'y2',
line = list(color = '#45171D')
) %>%

layout(title = 'New York Wind and Temperature Measurements for September 1973',
xaxis = list(title = ""),
yaxis = list(side = 'left', title = 'Wind in mph'),
yaxis2 = list(side = 'right', overlaying = "y", title = 'Temperature in degrees F'))

最佳答案

scatter 轨迹的 y 轴设置为 y2layout 中的 yaxis2覆盖 y

如果你想在背景中有scatter轨迹,反转y轴分配或在中将overlaying设置为y2 >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'))

enter image description here

关于r - 跟踪顺序 plotly R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54040078/

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