我想創建bar plot
(與plotly
包),其中(幾個月)將有red horizontal line
(獲得收益)。我希望下面的情節更加精確地顯示我的問題。水平線在R情節,當x軸是離散的
代碼和數據需要獲得第一條曲線:
library("plotly")
library("dplyr")
data.frame(miesiac_label = as.character(as.roman(c(1:12))),
miesiac = c(1:12),
ile = c(12000, 12100, 11100, 12000, 12000, 11900, 12200, 12100, 6000, 12100, 12100, 12100),
gain = c(rep(NA, 7), 11000, 12000, 12000, 12000, 12000)) -> dane
dane$miesiac_label <- factor(dane$miesiac_label, levels = dane[["miesiac_label"]])
plot_ly(dane) %>%
add_trace(x = ~miesiac_label, y = ~ile,
type = 'bar', marker = list(color = '#99d3df')) %>%
add_trace(x = ~miesiac_label, y = ~gain, name = 'Gain',
type = "scatter", mode='lines+markers', marker = list(color = 'red'),
line = list(color = 'red'))
我覺得我應該有連續的規模做到這一點,並在此之後只是改變x axis labels
,但我不知道如何以改變這些標籤(當然,我試圖在谷歌中找到它)...
非常感謝您的幫助!
你的代碼給我一個空的陰謀,你確定它是正確的嗎? –
@ MarijnStevering,是的,我剛剛再次爲你檢查過 - 這是正確的。 – Marta
啊,更新我的情節固定它,我的壞。 –