小编Wit*_*dow的帖子

闪亮:动态更改ggplot2中使用的列

我尝试创建一个Shiny应用程序,您可以在其中选择ggplot每个“ selectizeInput” 的x轴。

我知道Gallery示例,在这里可以通过预选所需的列来解决。因为我可能会动态更改x =属性,所以我希望数据结构有点复杂aes()

为了更好地理解,我添加了一个最小的工作示例。不幸的是,ggplot使用输入作为值,而是使用相应的列。

library(shiny)
library(ggplot2)


# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(

   # Application title
   titlePanel("Select x Axis"),       

   sidebarLayout(
      sidebarPanel(
        selectizeInput("xaxis", 
                       label = "x-Axis",
                       choices = c("carat", "depth", "table"))            
      ),          

      mainPanel(
         plotOutput("Plot")
      )
   )
))

server <- shinyServer(function(input, output) {

   output$Plot <- renderPlot({
     p <- ggplot(diamonds, aes(x = input$xaxis, y = price))
     p <-p + geom_point()
     print(p)
   })
})

# Run the …
Run Code Online (Sandbox Code Playgroud)

ggplot2 shiny

5
推荐指数
1
解决办法
716
查看次数

计算每组条件的行数

这段代码:

Group <- rep(c("A", "B", "C"), each = 3)
Days <- c(21,21,19,18,21,21,11,21,19)
State <- c("OK", "NOK", "OK", "OK", "NOK", "OK", "OK", "OK", "NOK")

data <- data.frame(Group = Group, Days = Days, State = State)
Run Code Online (Sandbox Code Playgroud)

创建此数据框:

> data
  Group Days State
1     A   21    OK
2     A   21   NOK
3     A   19    OK
4     B   18    OK
5     B   21    OK
6     B   21    OK
7     C   11   NOK
8     C   21    OK
9     C   19   NOK
Run Code Online (Sandbox Code Playgroud)

我经常使用group_bysummarizes …

r dplyr

3
推荐指数
1
解决办法
5037
查看次数

标签 统计

dplyr ×1

ggplot2 ×1

r ×1

shiny ×1