带有ggplot2的manipulateWidget

问题描述 投票:0回答:1

我正在尝试创建交互式ggplot2manipulateWidget似乎没有削减(下面的示例),还是?

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

r ggplot2
1个回答
0
投票

ggplot对象不是htmlwidget,因此不起作用。您可以使用ggiraph包将其转换为htmlwidget。

© www.soinside.com 2019 - 2024. All rights reserved.