r - 将 ggplot/manipulate 图转换为 plotly 或 js 脚本图
问题描述
我正在尝试使用 ggplotly() 将我的 ggplot 转换为情节图。但是,在对情节进行操作之后,它似乎不适用于此代码。还有其他方法吗?
library(ggplot2)
library(manipulate)
grades <- data.frame(Final = 20 * runif(70))
myFinalsPlot <- function(sliderInput, initialIndex, finalIndex) {
ggplot(data.frame(grades$Final[initialIndex:finalIndex]),
aes(x = grades$Final[initialIndex:finalIndex])) +
geom_histogram(aes(y = ..density..),
binwidth = sliderInput, colour = "green", fill = "yellow") +
geom_density(alpha = 0.2, fill = "#FF6666") +
labs(x = "Marks", y = "Grades")
}
myFinalsPlot <- manipulate(myFinalsPlot(slidersInput, 1, 70),
slidersInput = slider(1, 12, step = 1, initial = 5))
解决方案
首先,为了使您的代码与ggplot2
绘图一起工作,您的代码中存在需要修复的问题。您不应该为您的函数和绘图对象使用相同的名称。替换这个:
myFinalsPlot <- manipulate(myFinalsPlot(slidersInput, 1, 70),
slidersInput = slider(1, 12, step = 1, initial = 5))
通过,例如:
myPlot <- manipulate(myFinalsPlot(slidersInput, 1, 70),
slidersInput = slider(1, 12, step = 1, initial = 5))
现在,关于plotly
情节,我认为它不应该与操纵一起使用。我引用 RStudio 的网站https://support.rstudio.com/hc/en-us/articles/200551906-Interactive-Plotting-with-Manipulate:
RStudio 与操作包一起为标准R 绘图添加交互功能。
推荐阅读
- php - 在codeigniter中,如何通过将资产文件夹放在应用程序文件夹中来使其工作?
- reactjs - 如何更改现有记录?
- javascript - 如何使用窗口加载微调器样式百分比?百分比从 1 开始,当 100 是负载将结束并且我的页面将显示
- mongodb - Mongoose pre save hook is triggering while updating via Model.save()
- c - How to use MPI to transfer a custom struct with a dynamic array?
- node.js - 在非主分支上未通过语义发布生成自动更改日志
- html - 为什么“对象适合:覆盖;” 在这种情况下工作?
- reactjs - 如何解决 React Webpack 应用程序中的“找不到模块:错误:无法解析 ... multi @babel/polyfill ./react/index.js”
- ios - 我的代码不能在我的 iPad 上工作/一般不能工作
- javascript - 从另一个包导入时,导入返回 undefined