gpt4 book ai didi

r - 在 plot_ly 中覆盖散点区域

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

我想在一个图上绘制图表并绘制填充区域形状和条形图。然而,区域形状覆盖条。我无法更改元素的顺序。可以把酒吧带在前面吗?
enter image description here

data <- data.frame(years = c(2005,2006,2007), values1 = c(1,2,3), values2 = c(3,3,2))

plot_ly(data, x = data$years, y=data$values1, type = 'bar') %>%
add_trace(x=data$years, y=data$values2, type = 'scatter', mode = 'lines', fill = 'tozeroy')

最佳答案

这是改编自 answer通过@Maximilian Peters。这段代码

data <- data.frame(years = c(2005,2006,2007), values1 = c(1,2,3), values2 = c(3,3,2))

plot_ly(data) %>%
add_trace(x=~years, y=~values1, type = 'bar') %>%
add_trace( x = ~years, y=~values2, type = 'scatter', mode = 'lines', fill = 'tozeroy', yaxis='y2'
) %>%
layout(title = 'Trace order Plotly R',
xaxis = list(title = ""),
yaxis = list(side = 'left', title = 'Y - Axis', overlaying = "y2"),
yaxis2 = list(side = 'right', title = "" )
)
生成此输出:
output

关于r - 在 plot_ly 中覆盖散点区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62934870/

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