Vindaar / ggplotnim

A port of ggplot2 for Nim
https://vindaar.github.io/ggplotnim
MIT License
176 stars 15 forks source link

Date example #96

Closed lf-araujo closed 3 years ago

lf-araujo commented 3 years ago

Hi Vindaar,

First thank you for this excellent module.

For future reference, this is a common example of use of Date types in R that should improve the plotting ggplotnim capabilities. I believe this is perhaps more suited to be managed in a separate data management module.

So, for the data set:

https://gist.github.com/lf-araujo/5da7266c44b3824b824d578411dee73c

Where dates are arbitrarily entered, but one would usually want to print this out standardised as year, typical R code would use as.Date() and look like the following:

read.csv("finances.csv") %>% 
    ggplot(aes( x = as.Date(date), y = yrate)) +
         geom_line()+
         geom_point()

Resulting in:

image

However, current ggplotnim code would look like:

proc plot() = 
  let df = toDf(readCsv("./finances.csv"))
  ggplot(df, aes(x = "date")) + 
    geom_line(aes( y = "yrate")) + 
    ylab("Rate") +
    xlab(rotate = -45.0, margin = 1.75, alignTo = "right") +
    ggtitle("Rate evolution") +
    ggsave("finances.png")

and finances.png looks rather confusing:

finances

It is not handling negative values correctly and the dates are not standardised by year. This is currently not possible and not supported. This example is just for future testing.

Vindaar commented 3 years ago

Closing as duplicate.