Mik*_*ise 1 timezone r suppress-warnings ggplot2 axis-labels
这不是重复,因为该推定重复中的所有方法都不适用于此处.他们都没有导致警告消失.
事实上,我从下面的Konrad得到了答案 - 使用suppressMessages
.在断言作为可能重复的链接中,他们建议suppressWarnings
,这不起作用.
最后确定如何让R在ggplot
日期轴上正确使用我的时区(scale_x_datetime
在这里的帖子中找到,在它使用我的本地时区之前,即使数据已经设置了时区),但它现在抱怨警告:
Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.
Run Code Online (Sandbox Code Playgroud)
这很烦人,因为我必须做很多事情,并且不想养成忽略所有警告的习惯.我该怎么办呢?我显然已经尝试过suppressWarnings
(有和没有打印)和options(warn=-1).
scales_0.2.4
library(lubridate,quietly=T,warn.conflicts=T)
library(ggplot2,quietly=T,warn.conflicts=T)
library(scales,quietly=T,warn.conflicts=T)
sclip.time <- ymd_hms("2014-06-16 00:00:00",tz="US/Pacific")
eclip.time <- ymd_hms("2014-06-17 23:59:59",tz="US/Pacific")
sdata.time <- ymd_hms("2014-06-16 00:00:00",tz="US/Pacific")
edata.time <- ymd_hms("2014-06-17 23:59:59",tz="US/Pacific")
xdata <- seq(sdata.time,edata.time,length.out=100)
xfrac <- seq(0,4*3.1416,length.out=100)
ydata <- pmax(0.25,sin(xfrac))
ydata <- sin(xfrac)
ddf <- data.frame(x=xdata,y=ydata)
date_format_tz <- function(format = "%Y-%m-%d", tz = "UTC") {
function(x) format(x, format, tz=tz)
}
options(warn=-1)
suppressWarnings(
ggplot(ddf) +
geom_line(aes(x,y),col="blue") +
geom_vline(xintercept=as.numeric(sclip.time),color="darkred") +
geom_vline(xintercept=as.numeric(eclip.time),color="darkgreen") +
xlim(sclip.time,edata.time) +
scale_x_datetime( breaks = date_breaks("1 day"),
labels = date_format_tz("%Y-%m-%d %H:%M", tz="US/Pacific"))
)
Run Code Online (Sandbox Code Playgroud)
您必须使用以下代码段中的suppressMessages
和的组合print
:
suppressMessages(print(
ggplot(ddf) +
geom_line(aes(x,y),col="blue") +
geom_vline(xintercept=as.numeric(sclip.time),color="darkred") +
geom_vline(xintercept=as.numeric(eclip.time),color="darkgreen") +
xlim(sclip.time,edata.time) +
scale_x_datetime( breaks = date_breaks("1 day"),
labels = date_format_tz("%Y-%m-%d %H:%M", tz="US/Pacific"))
))
Run Code Online (Sandbox Code Playgroud)