【发布时间】:2017-04-21 02:34:35
【问题描述】:
我想创建一个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,但我不知道如何更改这些标签(我已经尝试先在谷歌中找到它,当然) ...
非常感谢您的帮助!
【问题讨论】:
-
你的代码给了我一个空白的情节,你确定它是正确的吗?
-
@MarijnStevering,是的,我刚刚为您再次检查过 - 正确。
-
啊,更新我的阴谋修复它,我的错。
-
不运行代码,你的问题在我看来就像可以用 ggplot2 中的
group处理的东西......我不知道情节上的等价物是什么,但也许这值得一看?