R POSIXct轴和滑块放入带有光泽的ggplot

R POSIXct轴和滑块放入带有光泽的ggplot,r,date,ggplot2,shiny,posixct,R,Date,Ggplot2,Shiny,Posixct,我是新手。我试着用sliderInput来表示ggplot和Shining的日期。我可以用动态图,而且很有效。但我希望坚持使用ggplot进行数据可视化。下面的R脚本可能很混乱。我就是不能让sliderInput在使用ggplot的闪亮应用程序上运行 数据集为 库(闪亮) 图书馆(比例尺) 图书馆(GG2) 图书馆(E2) #将系统语言设置为日语 Sys.setlocale(category=“LC_ALL”,locale=“Japanese”) #加载数据——数据集在上面的链接中可用。 df问

我是新手。我试着用sliderInput来表示ggplot和Shining的日期。我可以用动态图,而且很有效。但我希望坚持使用ggplot进行数据可视化。下面的R脚本可能很混乱。我就是不能让sliderInput在使用ggplot的闪亮应用程序上运行

数据集为

库(闪亮)
图书馆(比例尺)
图书馆(GG2)
图书馆(E2)
#将系统语言设置为日语
Sys.setlocale(category=“LC_ALL”,locale=“Japanese”)
#加载数据——数据集在上面的链接中可用。

df问题解决了。下面的脚本有效

library(shiny)
library(scales)
library(ggplot2)
library(reshape2)

# Set system language as Japanese
Sys.setlocale(category = "LC_ALL", locale = "Japanese")

# Load data ----
df <-read.csv("data.csv", encoding="UTF-8", stringsAsFactors=FALSE, check.names = F)
colnames(df)[1]<-"取引オープン日"  ##If the first column had extra string.

##Formating date
df$取引クローズ日edit<-gsub("/","-",df$取引クローズ日)
df$取引クローズ日edit<-as.POSIXct(df$取引クローズ日edit, format="%m-%d-%Y %H:%M") 

##Pick 5 columns
df_5col<-df[,c("ロット","総ピップス","総収益","ドローダウン(差額)","取引クローズ日edit")]

##Stack dataset
stacked<-melt(df_5col,id.vars="取引クローズ日edit",variable.name="USD/pips",value.name="USD/pips(値)")

stacked$取引クローズ日edit<-as.POSIXct(stacked$取引クローズ日edit, format="%m-%d-%Y %H:%M") 


# User interface ----
ui <- fluidPage(
  titlePanel("title"),
  sidebarLayout(
    sidebarPanel(
      helpText("Times-series data of FX autobot"),
      
      checkboxGroupInput("checkGroup", label = "Choose a variable to display", 
                         choices = c("総収益" = "総収益", "ドローダウン(差額)" = "ドローダウン(差額)", "総ピップス" = "総ピップス", "ロット" = "ロット"),
                         selected = "総収益"),
      
      sliderInput("sliderdate", 
                  label = "可視化する期間:",
                  min = as.POSIXct("2020-03-24 10:23"),
                  max = as.POSIXct(Sys.Date()),
                  value=c(as.POSIXct("2020-03-24 10:23"),
                          as.POSIXct("2020-12-30 10:23")),
                  timeFormat="%m-%d-%Y %H:%M")
    ),
    mainPanel(plotOutput("plot1"))
  )
)

# Server logic
server <- function(input, output) {
  output$plot1 <- renderPlot({
    
    ##create the data
    date1<-as.POSIXct(input$sliderdate, timeFormat="%m-%d-%Y %H:%M")
    
    sub_data <- subset(stacked, 取引クローズ日edit >= date1[1] & 取引クローズ日edit <= date1[2])
 
    sub_data2<-sub_data[sub_data[,2]%in%input$checkGroup,]
    ggplot(data=sub_data2) +geom_line(aes(x=取引クローズ日edit, y= sub_data2[,3], color=sub_data2[,2]))+ylab("USD/pips")+xlab("取引クローズ日")+scale_x_datetime(labels = date_format("%m-%d-%Y"),date_breaks = "1 month")
  })
  
}

# Run the app
shinyApp(ui, server)
库(闪亮)
图书馆(比例尺)
图书馆(GG2)
图书馆(E2)
#将系统语言设置为日语
Sys.setlocale(category=“LC_ALL”,locale=“Japanese”)
#加载数据----
df
library(shiny)
library(scales)
library(ggplot2)
library(reshape2)

# Set system language as Japanese
Sys.setlocale(category = "LC_ALL", locale = "Japanese")

# Load data ----
df <-read.csv("data.csv", encoding="UTF-8", stringsAsFactors=FALSE, check.names = F)
colnames(df)[1]<-"取引オープン日"  ##If the first column had extra string.

##Formating date
df$取引クローズ日edit<-gsub("/","-",df$取引クローズ日)
df$取引クローズ日edit<-as.POSIXct(df$取引クローズ日edit, format="%m-%d-%Y %H:%M") 

##Pick 5 columns
df_5col<-df[,c("ロット","総ピップス","総収益","ドローダウン(差額)","取引クローズ日edit")]

##Stack dataset
stacked<-melt(df_5col,id.vars="取引クローズ日edit",variable.name="USD/pips",value.name="USD/pips(値)")

stacked$取引クローズ日edit<-as.POSIXct(stacked$取引クローズ日edit, format="%m-%d-%Y %H:%M") 


# User interface ----
ui <- fluidPage(
  titlePanel("title"),
  sidebarLayout(
    sidebarPanel(
      helpText("Times-series data of FX autobot"),
      
      checkboxGroupInput("checkGroup", label = "Choose a variable to display", 
                         choices = c("総収益" = "総収益", "ドローダウン(差額)" = "ドローダウン(差額)", "総ピップス" = "総ピップス", "ロット" = "ロット"),
                         selected = "総収益"),
      
      sliderInput("sliderdate", 
                  label = "可視化する期間:",
                  min = as.POSIXct("2020-03-24 10:23"),
                  max = as.POSIXct(Sys.Date()),
                  value=c(as.POSIXct("2020-03-24 10:23"),
                          as.POSIXct("2020-12-30 10:23")),
                  timeFormat="%m-%d-%Y %H:%M")
    ),
    mainPanel(plotOutput("plot1"))
  )
)

# Server logic
server <- function(input, output) {
  output$plot1 <- renderPlot({
    
    ##create the data
    date1<-as.POSIXct(input$sliderdate, timeFormat="%m-%d-%Y %H:%M")
    
    sub_data <- subset(stacked, 取引クローズ日edit >= date1[1] & 取引クローズ日edit <= date1[2])
 
    sub_data2<-sub_data[sub_data[,2]%in%input$checkGroup,]
    ggplot(data=sub_data2) +geom_line(aes(x=取引クローズ日edit, y= sub_data2[,3], color=sub_data2[,2]))+ylab("USD/pips")+xlab("取引クローズ日")+scale_x_datetime(labels = date_format("%m-%d-%Y"),date_breaks = "1 month")
  })
  
}

# Run the app
shinyApp(ui, server)