【发布时间】:2019-10-26 17:10:10
【问题描述】:
我是闪亮的新手,我创建了一个应用程序,但是由于我的数据集很大,我的所有日期字段都被压缩在一起,用户无法读取,我想尝试绘制所选年份(2014 年)的每个特定日期以及与该日期、选定年份和国家/地区相关联的每个特定价格,但如果不在 csv 文件中组合我不想这样做的日期/年份,我似乎无法轻松做到这一点。
GGPLOT 示例:
我尝试过使用如下所示的 aes 代码,但即使将日期字段分配给 y 轴,也会发生同样的事情。
library(shiny)
library(ggplot2)
pigs <- read.csv("pigs_data.csv")
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Pig Breeding"),
sidebarLayout(
sidebarPanel(
#Allows user to choose a year which changes the distribution of plot points
selectInput(inputId = "year",
label = "Choose a year:",
choices = c(2014, 2015, 2016, 2017, 2018),
selectize = FALSE
)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("stats")
)
)
)
# Define server logic
server <- function(input, output) { #for the selectInput you can use the following observeEvent(input$year, {
output$stats <- renderPlot({
ggplot(pigs,
aes(x = price, y = date, col = country)) +
geom_jitter(width = 0.3) +
facet_grid(. ~input$year)
})
}
# Run the application
shinyApp(ui = ui, server = server)'
我希望该应用程序显示每个选定年份 (2014 年) 的单独日期 (23/04/14) 以及分配给每个国家/地区的特定价格 (123.40) 的情节点,即使这意味着过度绘图。
数据集示例:
【问题讨论】:
-
它被压扁了,因为“日期”列不是日期
-
csv 文件或绘图的 aes 编码中的日期列?
-
检查这个 - stackoverflow.com/questions/4310326/…,我也会使用
geom_line,因为有多个组并且它是连续的