Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 重新校准24小时X轴_R_Datetime_Ggplot2_Time Series_Timeserieschart - Fatal编程技术网

R 重新校准24小时X轴

R 重新校准24小时X轴,r,datetime,ggplot2,time-series,timeserieschart,R,Datetime,Ggplot2,Time Series,Timeserieschart,与此类似— 但是,当我试图重新对齐X轴以表示从6:00到6:00(而不是0:00到24:00)的数据时,它会弄乱X轴 数据: 图表: 在数据集中,时间变量的类是hms和difftime。您链接的解决方案需要将时间转换为因子类,以便用户可以指定级别的顺序 试试这个: # specify order for Time. In this case with 15 min intervals, the 25th position # for alphabetically sorted time is 0

与此类似—

但是,当我试图重新对齐X轴以表示从6:00到6:00(而不是0:00到24:00)的数据时,它会弄乱X轴

数据:

图表:


在数据集中,时间变量的类是
hms
difftime
。您链接的解决方案需要将时间转换为
因子
类,以便用户可以指定级别的顺序

试试这个:

# specify order for Time. In this case with 15 min intervals, the 25th position
# for alphabetically sorted time is 06:00:00
Time.order <- sort(as.character(intraday_txt_file$Time))[c(25:96, 1:24)]

# specify label breaks for x-axis by changing some to blanks. "by = 12" is for 3-hour breaks,
# since 12 x 15min interval = 3 hours. for 2-hour breaks, use "by = 8", etc.
Time.breaks <- Time.order
Time.breaks[setdiff(seq(1, 96), seq(1, 96, by = 12))] <- ""

ggplot(data=intraday_txt_file %>% mutate(Time = factor(Time, levels = Time.order)), 
       aes(x=Time, y=INTA_Lots_mean)) +
  geom_point() + geom_line() +
  geom_errorbar(aes(ymin=INTA_Lots_mean-INTA_Lots_std,
                    ymax=INTA_Lots_mean+INTA_Lots_std), width=.1) +
  scale_x_discrete(labels = Time.breaks)
#指定时间顺序。在这种情况下,每隔15分钟,第25个位置
#按字母顺序排序的时间为06:00:00

Time.order在数据集中,时间变量的类是
hms
difftime
。您链接的解决方案需要将时间转换为
因子
类,以便用户可以指定级别的顺序

试试这个:

# specify order for Time. In this case with 15 min intervals, the 25th position
# for alphabetically sorted time is 06:00:00
Time.order <- sort(as.character(intraday_txt_file$Time))[c(25:96, 1:24)]

# specify label breaks for x-axis by changing some to blanks. "by = 12" is for 3-hour breaks,
# since 12 x 15min interval = 3 hours. for 2-hour breaks, use "by = 8", etc.
Time.breaks <- Time.order
Time.breaks[setdiff(seq(1, 96), seq(1, 96, by = 12))] <- ""

ggplot(data=intraday_txt_file %>% mutate(Time = factor(Time, levels = Time.order)), 
       aes(x=Time, y=INTA_Lots_mean)) +
  geom_point() + geom_line() +
  geom_errorbar(aes(ymin=INTA_Lots_mean-INTA_Lots_std,
                    ymax=INTA_Lots_mean+INTA_Lots_std), width=.1) +
  scale_x_discrete(labels = Time.breaks)
#指定时间顺序。在这种情况下,每隔15分钟,第25个位置
#按字母顺序排序的时间为06:00:00

时间。订单谢谢你的改版。我永远也做不到。我想我需要快速眼动。对不起,谢谢你的重新格式化。我永远也做不到。我想我需要快速眼动。对不起,谢谢
# specify order for Time. In this case with 15 min intervals, the 25th position
# for alphabetically sorted time is 06:00:00
Time.order <- sort(as.character(intraday_txt_file$Time))[c(25:96, 1:24)]

# specify label breaks for x-axis by changing some to blanks. "by = 12" is for 3-hour breaks,
# since 12 x 15min interval = 3 hours. for 2-hour breaks, use "by = 8", etc.
Time.breaks <- Time.order
Time.breaks[setdiff(seq(1, 96), seq(1, 96, by = 12))] <- ""

ggplot(data=intraday_txt_file %>% mutate(Time = factor(Time, levels = Time.order)), 
       aes(x=Time, y=INTA_Lots_mean)) +
  geom_point() + geom_line() +
  geom_errorbar(aes(ymin=INTA_Lots_mean-INTA_Lots_std,
                    ymax=INTA_Lots_mean+INTA_Lots_std), width=.1) +
  scale_x_discrete(labels = Time.breaks)