R如何通过dplyr过滤器获得ggplot以进行颜色/形状
下面的代码可以工作(没有任何颜色/形状输入),但是尝试使点变成不同的形状/颜色被证明是困难的,我不确定问题出在哪里 我正在努力做到: 年份/范围在形状周围有黄色轮廓 产品/输入应为不同形状 身份/角色可以是不同的颜色R如何通过dplyr过滤器获得ggplot以进行颜色/形状,r,input,ggplot2,shiny,aesthetics,R,Input,Ggplot2,Shiny,Aesthetics,下面的代码可以工作(没有任何颜色/形状输入),但是尝试使点变成不同的形状/颜色被证明是困难的,我不确定问题出在哪里 我正在努力做到: 年份/范围在形状周围有黄色轮廓 产品/输入应为不同形状 身份/角色可以是不同的颜色 library(shiny) library(dplyr) library(shinydashboard) library(tidyverse) ui <- dashboardPage( dashboardHeader(title="Membership Satisfa
library(shiny)
library(dplyr)
library(shinydashboard)
library(tidyverse)
ui <- dashboardPage(
dashboardHeader(title="Membership Satisfaction"),
dashboardSidebar(
sidebarMenu(
menuItem("Demographics Dashboard", tabName = "demos", icon =
icon("dashboard"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "demos",
sidebarPanel(
checkboxGroupInput("inpt","Select variables to plot", choices =
c("Web" = 1,"Huddle" = 3, "Other" = 5,
"Test" = 7)),
checkboxGroupInput("role",
"Select Primary Role of Interest",
choices = c("Student" = 1, "Not" = 2)),
checkboxGroupInput("range",
"Select year(S) of Interest",
choices = c("2016"=2,"July 2017"=1))),
fluidPage(
plotOutput("plot")
# tableOutput("test")
)))))
当我尝试执行color=input$inpt或shape=input$inpt时,我得到一个错误“美学必须为长度1或与数据(3)相同:形状、颜色、大小”
有什么想法吗??谢谢 我尝试使用给定的数据运行代码,当我将颜色更改为
input$inpt
时,不会抛出错误。这个例子也有点复杂,这使得理解您正在尝试做什么和什么不起作用有点困难。你能举一个简单的例子来说明你想做什么吗?也可以考虑使用一个众所周知的数据集,如<代码> IRIS或<代码> MTCAS< /Cord>。@ BrianStamper,当您尝试添加一个角色时,它抛出了错误(学生/否)。我将尝试制作一个更简单的版本
server <- function(input,output){
library(tidyverse)
xPre <- reactive({
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
year %in% range)
})
yPre <- reactive({
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
year %in% range)
})
xPost<- reactive({
xPre<- xPre()
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
xPre %>%
filter(year %in% range,
Product %in% inpt,
status %in% role)%>%
group_by(Product, status,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
yPost<- reactive({
yPre <- yPre()
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
yPre %>%
filter(year %in% range,
Product %in% inpt,
status %in% role)%>%
group_by(Product, status,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
ySum <- reactive({
yPre <- yPre()
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
yPre %>%
filter(year %in% range,
Product %in% inpt)%>%
group_by(Product,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
xSum <- reactive({
xPre <- xPre()
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
xPre %>%
filter(year %in% range,
Product %in% inpt)%>%
group_by(Product,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
xyCoords<- reactive({
xPost <- xPost()
yPost <- yPost()
xSum <- xSum()
ySum <- ySum()
as.data.frame(matrix(c(xPost,xSum,yPost,ySum),ncol = 2))
})
output$test<- renderTable({
xyCoords <- xyCoords()
})
output$plot <- renderPlot({
xyCoords <- xyCoords()
xyCoords %>%
ggplot(aes(x=V1, y =V2 )) +
geom_point(colour = "blue", shape = 17, size = 5 )+
labs(x = "Mean Satisfaction", y = "Mean Importance") +
xlim(0,5) + ylim(0,5) +
geom_vline(xintercept=2.5) +
geom_hline(yintercept = 2.5)
})
}
shinyApp (ui = ui, server = server)
structure(list(status = c(1, 5, 5, 1, 1, 5), year = c(1, 1, 1,
1, 1, 1), Product = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1",
"2", "3", "4"), class = "factor"), Score = c(2, 5, 3, 5, 4, 4
)), .Names = c("status", "year", "Product", "Score"), row.names = c(NA,
6L), class = "data.frame")