【发布时间】:2018-10-03 08:04:51
【问题描述】:
我在R 中使用plot_ly,并尝试在下面创建这个简单的图表。我尝试表明观察到 2011 年之前的年份,并且预测 >= 2011 年的年份。问题始终是传说。
- 第一个情节:几乎是我想要的,但我无法删除“trace 4”图例条目。
- 第二个情节:我无法删除由“what”触发的图例
谁能解决这个问题?
library(plotly)
d1 <- structure(list(year = c(2006L, 2006L, 2006L, 2007L, 2007L, 2008L,
2008L, 2009L, 2009L, 2010L, 2010L, 2010L, 2011L, 2011L, 2012L,
2012L, 2012L, 2013L, 2013L, 2014L, 2014L, 2015L, 2015L, 2015L
), N = c(498, 500, 3890, 418, 3465, 311, 3740, 183, 3551, 363,
386, 3503, 368, 3577, 557, 235, 3397, 287, 3479, 484, 3601, 428,
311, 3509), part = c("1", "3", "9", "3", "9", "3", "9", "3",
"9", "0", "3", "9", "3", "9", "1", "3", "9", "3", "9", "3", "9",
"0", "3", "9")), .Names = c("year", "N", "part"), row.names = c(NA,
-24L), class = c("data.frame"))
# 1st plot
plot_ly() %>% add_trace(data = d1, x=~year, y=~N, color = ~part, mode="line") %>%
add_segments(x = 2010.5, xend = 2010.5, y = 0, yend = max(d1$N))
d1$what <- "obs"
d1$what[d1$year <= 2010] <- "fc"
# 2nd plot
plot_ly() %>% add_trace(data = d1, x=~year, y=~N, color = ~part, mode="line", linetype=~what)
谢谢! 曼努埃尔
【问题讨论】: