Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot2操纵边缘_R_Ggplot2 - Fatal编程技术网

R 使用ggplot2操纵边缘

R 使用ggplot2操纵边缘,r,ggplot2,R,Ggplot2,我正在尝试创建交互式ggplot2sManufactureWidget似乎并没有切断它(下面的示例),或者它会切断吗 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

我正在尝试创建交互式
ggplot2
s
ManufactureWidget
似乎并没有切断它(下面的示例),或者它会切断吗

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")
)
库(操纵窗口)
图书馆(绘本)
图书馆(GG2)

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

library(ggplot2)
library(ggiraph)
library(manipulateWidget)

myggplot <- function(type, lwd) {
  if (type == "points") {
    gg <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + 
      geom_point_interactive()
  } else {
    gg <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + 
      geom_line_interactive(size = lwd)
  }
  girafe(ggobj = gg)
}

manipulateWidget(
  myggplot(type, lwd),
  type = mwSelect(c("points", "lines"), "points"),
  lwd = mwSlider(1, 10, 1, .display = type == "lines")
)
库(ggplot2)
图书馆(ggiraph)
图书馆(操纵窗口)
myggplot