我正在尝试创建交互式ggplot2
。 manipulateWidget
似乎没有削减(下面的示例),还是?
library(manipulateWidget) library(plotly) library(ggplot2) mydata <- data.frame(x = 1:100, y = rnorm(100)) myPlot <- function(type, lwd) { if (type == "points") { plot_ly(mydata, x= ~x, y = ~y, type = "scatter", mode = "markers") } else { plot_ly(mydata, x= ~x, y = ~y, type = "scatter", mode = "lines", line = list(width = lwd)) } } myPlot("points") manipulateWidget( myPlot(type, lwd), type = mwSelect(c("points", "lines"), "points"), lwd = mwSlider(1, 10, 1, .display = type == "lines") ) myggplot <- function(type, lwd) { if (type == "points") { ggplot(mydata, aes(x, y)) + geom_point() } else { ggplot(mydata, aes(x, y)) + geom_line(size = lwd) } } myggplot("points") manipulateWidget( myggplot(type, lwd), type = mwSelect(c("points", "lines"), "points"), lwd = mwSlider(1, 10, 1, .display = type == "lines") )
如果是这样,有什么好的选择?
我正在尝试创建交互式ggplot2s。 handlerWidget似乎没有削减它(下面的示例),还是它? library(manipulateWidget)库(plotly)库(ggplot2)mydata
ggplot
对象不是htmlwidget,因此不起作用。您可以使用ggiraph
包将其转换为htmlwidget。