如何解决为什么我的 ggplot 图没有出现在闪亮的地方?
你好,我正在为一个班级项目做这个 Shiny 应用程序,我想知道为什么我的图表根本没有出现。它运行时没有出现错误并显示侧面板,但图形显示为空白。我附上了下面的代码。我在这里看到了其他与我们有关的帖子,我已经尝试过了,但没有任何内容给我所需的结果。我只需要这个在周二之前出现,所以我可以在周四早上提交。谢谢!
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
# Load Libraries
library(shiny)
library(tidyverse)
library(ggrepel)
library(dplyr)
library(magrittr)
library(quantmod)
# Load and Merge Data
wordbank = read_csv("/Users/Dohyun/Desktop/school stuff/year3/stat41/final project/administration_data.csv")
wordbank
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Word Bank"),# Sidebar layout with a input and output deFinitions
sidebarLayout(
# Inputs: Select variables to plot
sidebarPanel(
selectInput(inputId = "x",label = "X-axis:",choices = c("Age" = "age")),selectInput(inputId = "y",label = "Y-axis:",choices = c("Word Size" = "comprehension")),selectInput(inputId = 'language','Language: ',choices = c("English (American)","English (British)","English (Australian)","American Sign Language","British Sign Language","Cantonese","Croatian","Czech","Danish","french (french)","french (Quebecois)","German","Greek (Cypriot)","Hebrew","Italian","Kigiriama","Kiswahili","Korean","Latvian","Mandarin (Beijing)","Mandarin (Taiwanese","norwegian","Portugeuse (European)","Russian","Slovak","Spanish (European)","Spanish (Mexican)","Swedish","Turkish")),sliderInput(inputId = "alpha",label = "Alpha:",min = 0,max = 1,value = 0.5)
),#Output
mainPanel(
plotOutput(outputId = "scatterplot"),plotOutput(outputId = "Boxplot"),br(),# a little bit of visual separation
)
)
)
# Define server function --------------------------------------------
server <- function(input,output) {
lang_data <- reactive({
wordbank %>%
filter(language %in% input$language)
})
# Create scatterplot object the plotOutput function is expecting
output$lang_plot <- renderPlot({
# Creates base plot
p1 <-
ggplot(lang_data(),aes(x = input$x,y = input$y,fill = as.factor(age))) +
geom_Boxplot(alpha = .6,outlier.shape = NA) +
geom_jitter(size = 0.2,alpha = input$alpha,width = 0.3,aes(color = as.factor(age))) +
scale_fill_viridis_d(end = .75,option = "D",guide=FALSE) +
scale_color_viridis_d(end = .75,guide=FALSE) +
labs(x = str_to_title(str_replace_all(input$x,"_"," ")),y = str_to_title(str_replace_all(input$y," "))) +
scale_x_continuous(breaks = seq(from = 16,to = 30,by = 2))
theme(panel.background = element_blank())
print(p1)
})
}
# Create the Shiny app object ---------------------------------------
shinyApp(ui,server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。