R geom_烛台未按自己的数据编辑方式打印:将POSIXct转换为日期
我有一些价格数据,我正试图用以下方法绘制R geom_烛台未按自己的数据编辑方式打印:将POSIXct转换为日期,r,R,我有一些价格数据,我正试图用以下方法绘制geom_烛台图表: 套餐:tidyquant df %>% subset(date < "2019-01-24 15:30:00" & date >= "2019-01-24 14:40:00") %>% ggplot(aes(x = date, y = close)) + geom_candlestick(aes(open = open, high = high, low = low, clos
geom_烛台
图表:
套餐:tidyquant
df %>%
subset(date < "2019-01-24 15:30:00" & date >= "2019-01-24 14:40:00") %>%
ggplot(aes(x = date, y = close)) +
geom_candlestick(aes(open = open, high = high, low = low, close = close),
color_up = "darkgreen", color_down = "darkred",
fill_up = "darkgreen", fill_down = "darkred") +
theme_tq()
df%>%
子集(日期<“2019-01-24 15:30:00”和日期>=“2019-01-24 14:40:00”)%%
ggplot(aes(x=日期,y=结束))+
geom_烛台(aes(打开=打开,高=高,低=低,关闭=关闭),
color\u up=“暗绿色”,color\u down=“暗绿色”,
fill_up=“暗绿色”,fill_down=“暗绿色”)+
主题_tq()
它不会像它应该的那样绘制开放、高、低和关闭
然而,以下工作:
AAPL <- tq_get("AAPL",
get = "stock.prices",
from = "2015-09-01",
to = "2016-12-31")
AAPL %>%
subset(date < "2015-11-04" & date >= "2015-10-01") %>%
ggplot(aes(x = date, y = close)) +
geom_candlestick(aes(open = open, high = high, low = low, close = close)) +
labs(title = "AAPL Candlestick Chart",
subtitle = "Zoomed in using coord_x_date",
y = "Closing Price", x = "") +
theme_tq()
AAPL%
子集(日期<“2015-11-04”和日期>=“2015-10-01”)%%
ggplot(aes(x=日期,y=结束))+
geom_烛台(aes(打开=打开,高=高,低=低,关闭=关闭))+
实验室(title=“AAPL烛台图”,
subtitle=“使用坐标x日期放大”,
y=“收盘价”,x=“”)+
主题_tq()
两个数据帧的结构相同。我哪里出错了
数据:
df有几件事:
1) 在第一个代码块中,有两个管道(df%%>%%>%subset()
)。一定要把它清理干净
2) 如果您检查子集,您将看到您没有返回任何数据——因此,为什么没有绘制任何信息。比如说,
df %>%
subset(date < "2019-01-24 17:20:00" & date >= "2019-01-24 16:05:00") %>% View()
df%>%
子集(日期<“2019-01-24 17:20:00”和日期>=“2019-01-24 16:05:00”)%%>%View()
将返回一个空数据帧。在您提供的数据帧中,没有晚于09:15:00
的时间戳,因此请求16:50
和17:20
之间的数据是空的
你可以注释掉你的subset()
行,你会得到一个绘图。结构不同:df
中的date
是POSIXct
,而在AAPL
中它是date
。不过,我不确定是否有一个简单的解决方案。我明白了。你是对的。应用-as.Date(as.POSIXct(x$Date,'GMT'))
也不会返回小时数。格式(df$Date,“%Y-%m-%d%H:%m:%S,'CET”)
-我相信它会以正确的格式将日期存储为字符。然后应用这个-(df$date2感谢您的回复!我已经整理出了第1点。第2点:数据从>c(最小(df$date),最大(df$date))[1]“2019-01-24 14:40:00 CET”“2019-01-24 16:15:00 CET”
。我还将更新子集
df %>%
subset(date < "2019-01-24 17:20:00" & date >= "2019-01-24 16:05:00") %>% View()