r - R-plotly中带有堆积面积图的叠加线
问题描述
有没有办法在 Plotly R 中用堆积面积图覆盖一条线?这是示例代码,但它并没有让我得到我想要的。我希望这条线不要堆叠在面积图上,而是独立的。它类似于供需问题。
library(plotly)
data <- t(USPersonalExpenditure)
data <- data.frame("year"=rownames(data), data)
data$test <- 200
fig <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco',
type = 'scatter', mode = 'lines', stackgroup = 'one', fillcolor = '#F5FF8D')
fig <- fig %>% add_trace(y = ~Household.Operation, name = 'Household Operation',
fillcolor = '#50CB86')
fig <- fig %>% add_trace(y = ~Medical.and.Health, name = 'Medical and Health',
fillcolor = '#4C74C9')
fig <- fig %>% add_trace(y = ~Personal.Care, name = 'Personal Care',
fillcolor = '#700961')
fig <- fig %>% add_trace(y = ~Private.Education, name = 'Private Education',
fillcolor = '#312F44')
fig <- fig %>% layout(title = 'United States Personal Expenditures by Categories',
xaxis = list(title = "", showgrid = FALSE),
yaxis = list(title = "Expenditures (in billions of dollars)",
showgrid = FALSE))
fig %>%
add_lines(x= data$year, y = 200)
解决方案
推荐阅读
- android - 如何在android中创建自定义弹出菜单设计
- javascript - 在 promise 返回方法输出中包装一个 promise
- reporting-services - 当行不包含任何数据时隐藏列表中的行
- c - 字节大小不匹配:将结构中的字符数组写入 C 中的二进制文件
- c++ - 为什么我的代码没有将每个对象都添加到向量中?
- git - 与来自外国的未知用户相关的 Git 提交
- python - 为什么python id中的输出很奇怪
- openstack - 更改活动实例中的密钥对
- c++ - 最大公因数函数
- node.js - 来自 NodeJS / Express 服务器的神秘消息 GET 200