library(duckdb)
## 필요한 패키지를 로딩중입니다: DBI
library(ggplot2)
setwd("C:/work/data")


con <- dbConnect(duckdb(), dbdir="testdb", read_only= TRUE)
res <- dbGetQuery(con, "select dd, cls from day_stk_h where nm ='삼성전자'")
print(res)
##          dd   cls
## 1  20241025 55900
## 2  20241024 56600
## 3  20241023 59100
## 4  20241022 57700
## 5  20241021 59000
## 6  20241018 59200
## 7  20241017 59700
## 8  20241016 59500
## 9  20241015 61000
## 10 20241014 60800
## 11 20241011 59300
## 12 20241010 58900
## 13 20241008 60300
## 14 20241007 61000
## 15 20241004 60600
## 16 20241002 61300
res <- dbGetQuery(con, "select dd, cls from day_stk_h where nm ='삼성전자' order by dd")
print(res)
##          dd   cls
## 1  20241002 61300
## 2  20241004 60600
## 3  20241007 61000
## 4  20241008 60300
## 5  20241010 58900
## 6  20241011 59300
## 7  20241014 60800
## 8  20241015 61000
## 9  20241016 59500
## 10 20241017 59700
## 11 20241018 59200
## 12 20241021 59000
## 13 20241022 57700
## 14 20241023 59100
## 15 20241024 56600
## 16 20241025 55900
df_data <- res 
str(df_data)
## 'data.frame':    16 obs. of  2 variables:
##  $ dd : chr  "20241002" "20241004" "20241007" "20241008" ...
##  $ cls: num  61300 60600 61000 60300 58900 59300 60800 61000 59500 59700 ...
ggplot(df_data, aes(x=dd, y=cls, group=1)) + geom_line() +theme(axis.text.x =element_text(angle=90,hjust=1))