[R] Problems plotting a sparse time series in R

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Oct 29 16:32:10 CET 2012


On Mon, Oct 29, 2012 at 10:14 AM, Alexander Engelhardt
<alex at chaotic-neutral.de> wrote:
> Hi guys,
>
> I am logging data about my body (weight, body fat, blood pressure, ..) in a
> .csv file and would like to plot this as a time series. I uploaded the
> (noisified) .csv, you can see the link in the code I have so far (you can
> run the code directly as-is):
>
>     df.raw <-
> read.csv("http://www.chaotic-neutral.de/temp/stats-noised.csv", sep=";",
> dec=".")
>     date <- as.Date(df.raw[,1])
>     comments <- df.raw[,2]
>     stats <- df.raw[,-c(1,2)]
>
>     ################################################################
>     #### timeSeries
>     library(timeSeries)
>     ts <- timeSeries(charvec=date, data=stats)
>     plot(ts)
>
>     ################################################################
>     #### zoo
>     library(zoo)
>     ts <- zoo(stats, date)
>     plot(ts)
>
Thanks for the reproducible example.

> I tried plotting the stuff with two packages, timeSeries and zoo. Both have
> the same problem: The column "Bauchfalte" which has a lot of entries (I
> measure this constantly), gets plotted, but the other ones don't. Most of
> them have only two entries and a lot of NAs, so I would at least expect a
> straight line between the two dates in those plots.
>
> Maybe there is a problem with determining the ylim of the plots of the
> sparse columns, this is what an error message said. But I have no idea how
> to fix this.
>
> Does anyone have an idea what's wrong here?
>
I'm not 100% certain, but I think plot.zoo only plots _consecutive_
observations as lines.

> Also, if you have suggestions if there is a better format or way to log my
> data, I would appreciate that as well. I just figured the current way of one
> central date column and a lot of NAs for stuff I don't measure that day is
> the best way, because I'd like to add vertical lines at the dates with an
> entry in the "comment" column in every plot.
>
I would plot the sparse data as points, not lines.  For example:
plot(ts, screens=1, type=c("l",rep("p",4)), col=rainbow(5))

> Thanks a lot!
>  - Alex
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com




More information about the R-help mailing list