R ggplot2本地和托管输出之间的差异

R ggplot2本地和托管输出之间的差异,r,ggplot2,shiny,R,Ggplot2,Shiny,我注意到本地输出和闪亮的应用程序之间的ggplot呈现有一个意想不到的差异。轴标签完全不同: 本地: 闪亮应用程序: 两幅图的轴线相差整整一天——真奇怪!在发布到Shining的过程中发生了什么 资料 服务器.R library(ggplot2) library(scales) shinyServer( function(input, output){ output$plot <- renderPlot({ data.df <- base &l

我注意到本地输出和闪亮的应用程序之间的
ggplot
呈现有一个意想不到的差异。轴标签完全不同:

本地: 闪亮应用程序:

两幅图的轴线相差整整一天——真奇怪!在发布到Shining的过程中发生了什么

资料 服务器.R

library(ggplot2)
library(scales)
shinyServer(
  function(input, output){
    output$plot <- renderPlot({
      data.df <- 
      base <- ggplot(data.df, aes(Report.Date, value))
      plot <- base + geom_area(aes(group = variable, fill= variable), position = 'identity') + geom_point(aes(color = series), color = "black")
      plot <- plot + xlab("Date") + ylab("Number of Deposits/Published")
      plot  +
        scale_y_continuous(breaks = seq(0,round(max(data.df$value)+5,-1),5)) +
        scale_x_datetime(breaks = "1 month", labels = date_format("%d-%b-%Y"), minor_breaks = "1 month") + 
        theme(axis.text.x = element_text(angle = 45, hjust = 1))
    }
    )
  }
)
库(ggplot2)
图书馆(比例尺)
shinyServer(
功能(输入、输出){

输出$plot1430434800秒,因为Unix时代是2015年4月30日格林威治标准时间23:00:00,这是一天即将结束的危险时刻

tz
as.POSIX*
函数的
参数丢失或为空字符串时

看起来你现在在格林尼治标准时间或西部,而R Shining server则在格林尼治标准时间+1或东部。这两台计算机将相同的固定时间点计算为不同的“挂钟”时间,并且由于参考点接近午夜,因此存在人为的日期更改

要解决这个问题,您应该提供时区定义,这样POSIX*函数就不必返回到不可预测的默认值

看起来您可以通过给
tzone
属性一个“GMT”值来实现这一点:


data.df太棒了!谢谢,我会研究一下这个问题——正如你所看到的,我是GMT,所以我会在早上试试这个。这对我来说很有效——我想值得注意的是,
ggplot2
上有一个关于“scale\u x\u datetime将POSIXct转换为本地时区”的问题,我在事后发现,你给了我关于时区的帽子提示-
library(ggplot2)
library(scales)
base <- ggplot(data.df, aes(Report.Date, value))
plot <- base + geom_area(aes(group = variable, fill= variable), position = 'identity') + geom_point(aes(color = series), color = "black")
plot <- plot + xlab("Date") + ylab("Number of Deposits/Published")
plot  +
  scale_y_continuous(breaks = seq(0,round(max(data.df$value)+5,-1),5)) +
  scale_x_datetime(breaks = date_breaks("1 month"), labels = date_format("%Y-%b-%d"), minor_breaks = "1 month") + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
shinyUI(
  fluidPage(
    plotOutput("plot")
  )
)
library(ggplot2)
library(scales)
shinyServer(
  function(input, output){
    output$plot <- renderPlot({
      data.df <- 
      base <- ggplot(data.df, aes(Report.Date, value))
      plot <- base + geom_area(aes(group = variable, fill= variable), position = 'identity') + geom_point(aes(color = series), color = "black")
      plot <- plot + xlab("Date") + ylab("Number of Deposits/Published")
      plot  +
        scale_y_continuous(breaks = seq(0,round(max(data.df$value)+5,-1),5)) +
        scale_x_datetime(breaks = "1 month", labels = date_format("%d-%b-%Y"), minor_breaks = "1 month") + 
        theme(axis.text.x = element_text(angle = 45, hjust = 1))
    }
    )
  }
)