r - 在ggplotly上添加第二个Y轴
问题描述
我使用 plotly 和 ggplot 创建了以下数据框对象和图形
library(ggplot2)
library(plotly)
rdate <- function(x,
min = paste0(format(Sys.Date(), '%Y'), '-01-01'),
max = paste0(format(Sys.Date(), '%Y'), '-12-31'),
sort = TRUE) {
dates <- sample(seq(as.Date(min), as.Date(max), by = "day"), x, replace=TRUE)
if (sort == TRUE) {
sort(dates)
} else {
dates
}
}
DF<-data.frame(Date = rdate(100))
DF$variable<-LETTERS[seq( from = 1, to = 10 )]
DF$Value<-round(runif(1:nrow(DF),min = 10, max = 50))
接下来我用 ggplot 创建了一个绘图对象
p <- ggplot(DF, aes(x = Date, y = Value, colour = variable)) +
geom_line() +
ylab(label="Sellcount") +
xlab("Sell Week")
p<-p + scale_y_continuous(sec.axis = dup_axis())
ggplotly(p)
如果我使用 plot(p) 绘制 p,则该图有 2 个 yaxes,如我所料。但是,当我使用 ggplotly(p) 绘制图形时,只生成了一个 Y 轴。我无法在互联网上找到任何与此相关的文献。我请求有人在这方面帮助我。
解决方案
推荐阅读
- r - 如何计算所有可能波段组合中的归一化比率指数,然后与 R 中的环境变量相关?
- angular - ./src/polyfills.ts 中的错误未找到模块:错误:无法解析“zone.js/dist/zone”
- swift - 如何在 Swift 中测量 DispatchQueue 并发异步中的代码块执行时间?
- python - 在 Pyspark Rdd 映射函数中传递 python 类对象
- ruby-on-rails - 如何在 Ruby on rails 中创建动态哈希数组
- node.js - 如何将 1 存储为 Double mongoose,mongodb?
- assembly - 使用 SSE4.1 的 8 × 16 位整数向量的高效校验和
- javascript - 加载屏幕时如何将子属性/值传递给父组件
- java - 如何修复构建 Android 中的错误:使用未声明的标识符“V4L2_COM_CMD_FLUSH”
- reactjs - 移动屏幕,屏幕下方可见