我想创建一个bar plot
(带有plotly
包),它(几个月)将拥有red horizontal line
(获得)。我希望,下面的图表更准确地显示了我的问题。
获取第一个图所需的代码和数据:
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
,但我不知道如何改变那些标签(当然,我首先尝试在谷歌中找到它)......
非常感谢你的帮助!