R的长度必须为1或与数据(8):y相同
我尝试在R中绘制多个折线图,并包含复选框,但当我尝试选择多个时,会收到一条错误消息: 错误:长度必须为1或与数据(8):y相同 我能够在使用单选按钮时无误地绘制它们,但复选框不起作用。这是我的密码:R的长度必须为1或与数据(8):y相同,r,shiny,R,Shiny,我尝试在R中绘制多个折线图,并包含复选框,但当我尝试选择多个时,会收到一条错误消息: 错误:长度必须为1或与数据(8):y相同 我能够在使用单选按钮时无误地绘制它们,但复选框不起作用。这是我的密码: library(readxl) scores <- read.csv("newscores.csv") weeks <- read.csv("weeks.csv") library(ggplot2) # ui.R fluidPage( # Give the page a
library(readxl)
scores <- read.csv("newscores.csv")
weeks <- read.csv("weeks.csv")
library(ggplot2)
# ui.R
fluidPage(
# Give the page a title
titlePanel("Fantasy Scores"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
checkboxGroupInput("Team", label = h3("Select Team"),
choices = c("Jeff","Jordan","Emmerts",
"CJ","Jimmy","Phil",
"Mat","Clegg","Rob","Shawn",
"Seth","Truscott"))
),
# Create a spot for the barplot
mainPanel(
plotOutput("phonePlot")
)
)
)
# server.R
function(input, output) {
# Fill in the spot we created for a plot
output$phonePlot <- renderPlot({
# Render a barplot
ggplot(weeks, aes(x = Week, y = weeks[,input$Team])) +
geom_point() + geom_line()+ylim(59,160)+labs(title="Scores by Week",
x="Week",y="Points")+theme_minimal()
})
}
谢谢你的帮助 这是一个解决方案:
library(reshape2)
library(dplyr)
library(ggplot2)
#input <- NULL
#input$Team <- c("Seth", "Truscott")
weeks_melt <- melt(weeks, "Week")
p <- ggplot(weeks_melt, aes(x = Week, y = value, color = variable)) + geom_blank()
weeks_filtered <- week_melt %>% filter(variable %in% input$Team)
p + geom_line(data = weeks_filtered)
library(重塑2)
图书馆(dplyr)
图书馆(GG2)
#输入请不要包括代码和数据的链接。该示例足够小,可以一字不差地包含在内(如果您希望它是一个MWE,那么做得很好!)。但是,如果/当链接过时,此问题将无法重现。你能用实际的代码和10行数据替换你的github链接吗?谢谢你的提示!刚刚更新了帖子,包含了所有必要的信息。请使用dput(head(weeks))
以便于复制。
library(reshape2)
library(dplyr)
library(ggplot2)
#input <- NULL
#input$Team <- c("Seth", "Truscott")
weeks_melt <- melt(weeks, "Week")
p <- ggplot(weeks_melt, aes(x = Week, y = value, color = variable)) + geom_blank()
weeks_filtered <- week_melt %>% filter(variable %in% input$Team)
p + geom_line(data = weeks_filtered)