[英]How to plot week for each year on x axis in plot_ly.(R Language)
我有一個數據集如下:
我想為 X 軸繪制 Y 軸上的實際值和擬合值,這將顯示周和年。
我創建了一個名為 Year_Week 的新變量並嘗試繪制它,因為它的 x 軸采用升序數據。 數據繪制正確,但我正在為 X 軸的命名而苦苦掙扎。
這是我正在使用的 plot_ly 代碼。
output$plot_forecast <- renderPlotly({
data <- forecast_data()
plot <- plot_ly(data, type = "scatter", mode = 'lines') %>%
add_lines(x = ~ data$year_week,
y = ~ data$actual,
name ="Actual",
line=list(color="Red")) %>%
add_lines(x = ~ data$year_week,
y = ~ data$fitted,
name ="Predicted",
line=list(color="Green")) %>%
layout(title = "Total Sales (Actual vs Predicted)",
xaxis = list(title = "Year Week"),
yaxis = list (title = "Total POS Sales"),
legend = list(x = 100, y = 0.5))
return(plot) })
x 軸當前顯示 201.49K 表示 2014 年的第 9 周,201.53K 表示 2015 年的第 3 周。
我需要 x 軸比這些數字更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.