You are not logged in.

#1 2017-01-15 18:00:06

DarkDeepBlue
Member
Registered: 2017-01-15
Posts: 4

Visualization tool needed

Hello people,

I have data of the form

2017-01-15 17:23:38  2.12
2017-01-15 17:27:14 13.30
2017-01-15 17:31:49 10.49
2017-01-15 17:31:49  7.82
2017-01-15 18:22:56  1.64

in a file and I'm looking for a convenient way to visualize the values in the third column over the timeline including the time in the middle column.

What is the best tool to archieve this?

Offline

#2 2017-01-15 18:03:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: Visualization tool needed

There are any number of tools.  LOffice has a spreadsheet program that would do this much like excel would.  Gnuplot could almost certainly do it.  I'd use R or Sweave (R + LaTeX), most likely with the tikz graphics device output.

If you don't care too much about the x-axis labels, something as simple as the following R code would work:

d = read.table("/path/to/file")
plot(d$V3, type="l")

Note "V3" is the default column name assigned to the 3rd data column when no names are provided in the file or to the read.table function.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2017-01-15 18:15:00

DarkDeepBlue
Member
Registered: 2017-01-15
Posts: 4

Re: Visualization tool needed

Thank you for the example.
I saw all the examples regarding R, but it’s something completly different to have something minimal to build on.

Offline

#4 2017-01-15 18:18:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: Visualization tool needed

That is indeed a *very* minimal example.  You can do a lot to tweak plots in R, feel free to ask if there are specific needs that you're not sure how to address.

I will admit that getting address+timestamp x-axis labels is not trivial.  It's not really hard, but just not trivial as R would count those strings as factors by default which would result in a boxplot instead of a line plot.  I make plots of project enrollment over time with both daily enrollment and a running total with separate left and right y axes, with nice labels, coloring, vertical bars dividing months, etc.  That is a much more invovled script, but very doable in R once you learn a bit of how it works.

If you just want to get a feel for the "shape" of the data, the above minimal example may be sufficent.  But if you want to present this to others, you'll certainly want to add some polish.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2017-01-15 18:39:50

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,715

Re: Visualization tool needed

gnuplot -p -e 'set xdata time; set timefmt "%Y-%m-%d %H:%M:%S"; plot "/dev/stdin" using 1:3 t "time" ' < test.dat

Edit:  Figures, whilst I'm off figuring it out, Trilby gets it done smile

Last edited by ewaller (2017-01-15 18:42:42)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#6 2017-01-15 21:46:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: Visualization tool needed

The gnuplot solution has a couple of clear advantages.  First I neglected the fact that the input might not be in sorted order, and second, my simple approach discards the x axis scale as it just treats the third column as a series of data.

I don't - off the top of my head - know the R function for reading time data but I'm sure there is one (format looks promising, but my first naive attempt didn't work as I expected) but basically you'd just modify the second line of R cod to be more like:

plot(d$V3~strtodate(paste(d$V1,d$V2)), type="l")

the strtodate is a placeholder for a function that takes a string with a date and converts it into something more usable as a scale (a epoch-time timestamp for example).


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB