使用R的组数据的交互式绘图

时间:2021-08-29 20:15:03

All,

所有,

In order to graph data in many groups(categories):

为了绘制许多组(类别)中的数据:

data(iris)
library(dplyr)
iris_new <- select(iris, -Species)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + 
        geom_point(data = iris_new, colour = "grey70") +
        geom_point(aes(colour = Species)) +
        facet_wrap(~Species)

使用R的组数据的交互式绘图

I didn't make interactive plots before, but I would like to know a way to allow me to make the above graph interactively. For example, in stead of showing the data using facet, I would like to have a bottom-like thing or scroll down list function that I can click on to highlight the data of different groups interactively. Each time I click on a certain group name (like those used for the legend), I can see the group data are highlighted and other data are greyed out. Any ideas here? Thank you.

我之前没有制作过互动图,但我想知道一种让我以交互方式制作上图的方法。例如,我希望有一个类似于底部的东西或向下滚动列表功能,我可以点击以交互式地突出显示不同组的数据。每次我点击某个组名(如用于图例的组名)时,我都会看到组数据突出显示,其他数据显示为灰色。这里有什么想法?谢谢。

1 个解决方案

#1


1  

You can make interactive displays via shiny. See here: https://shiny.rstudio.com/

您可以通过闪亮进行交互式显示。见这里:https://shiny.rstudio.com/

Here's code that you can run:

这是您可以运行的代码:

library(shiny)
library(dplyr)
library(ggplot2)
data(iris)

ui <- fluidPage(
  selectInput('species','Species',c("setosa","versicolor","virginica")),
  plotOutput("plot")
)

server <- function(input, output) {
  iris_new <- select(iris, -Species)

  output$plot <- renderPlot({
    ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + 
      geom_point(data = iris_new, colour = "grey70") +
      geom_point(data=iris[iris$Species==input$species,],aes(colour = Species))
  })


}

shinyApp(ui = ui, server = server)

#1


1  

You can make interactive displays via shiny. See here: https://shiny.rstudio.com/

您可以通过闪亮进行交互式显示。见这里:https://shiny.rstudio.com/

Here's code that you can run:

这是您可以运行的代码:

library(shiny)
library(dplyr)
library(ggplot2)
data(iris)

ui <- fluidPage(
  selectInput('species','Species',c("setosa","versicolor","virginica")),
  plotOutput("plot")
)

server <- function(input, output) {
  iris_new <- select(iris, -Species)

  output$plot <- renderPlot({
    ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + 
      geom_point(data = iris_new, colour = "grey70") +
      geom_point(data=iris[iris$Species==input$species,],aes(colour = Species))
  })


}

shinyApp(ui = ui, server = server)