1
$\begingroup$

There is a dataset: for each year a single data for 6 seas. I would like to have a graph to visualize paralel changes.

This is what I attempted to reproduce http://www.eea.europa.eu/data-and-maps/daviz/annual-average-sea-surface-temperature-1#tab-chart_1

I imported tsv file, made some corrections.

enter image description here

ListPlot looks almost nice, but on x-axis I have only natural numbers, not the years.

I also tried DateListPlot, but it did not accept just years.

datedata = 
 Map[Rest, 
   Rest@SST] /. {a_, b_, c_, d_, e_, f_, 
    g_} -> {{a, b}, {a, c}, {a, d}, {a, e}, {a, f}, {a, g}}

{{{1870, -0.59}, {1870, -0.53}, {1870, -0.33}, {1870, -0.44}, {1870, 
-0.43}, {1870, -0.59}}, {{1871, -0.6}, {1871, -0.57}, {1871, -0.33}, 
{1871, -0.47}, {1871, -0.43}, {1871, -0.56}}, {{1872, -0.58}, {1872, 
-0.65}, {1872, -0.34}, {1872, -0.5}, {1872, -0.41}, {1872, -0.55}}, 
{{1873, -0.55}, {1873, -0.62}, {1873, -0.3}, {1873, -0.45}, {1873, 
-0.39}, {1873, -0.5}}, ...

Inserting some fake month and day still not helped.

data[[1]]

{{{1870, 1, 1}, -0.59}, {{1870, 1, 1}, -0.53}, {{1870, 1, 
   1}, -0.33}, {{1870, 1, 1}, -0.44}, {{1870, 1, 1}, -0.43}, {{1870, 
   1, 1}, -0.59}}

enter image description here

$\endgroup$
2
  • $\begingroup$ The format for ListPlot is {{x,y},{x,y},{x,y}...}. x in your case is the year corresponding to the measured anomaly y. For example plotting the list in your code block will actually work - if you plot that the year will appear on the x axis. $\endgroup$
    – C. E.
    Mar 14, 2015 at 22:52
  • $\begingroup$ I've already tried, but it ruins coloring $\endgroup$
    – Vica
    Mar 14, 2015 at 23:08

1 Answer 1

5
$\begingroup$
data = Import["http://www.eea.europa.eu/data-and-maps/daviz/annual-average-sea-surface-temperature-1/download.csv"];

Process the imported data to remove the first (empty) column and the first (header) row, and separate column 1 from the rest:

{times, states} = {#[[All, 1]], #[[All, 2 ;;]]} &@Rest[Rest /@ data];

labels = {"Global ocean", "Baltic Sea", "North Atlantic", "North Sea",
"Mediterranean Sea", "Black Sea"};

Create a TemporalData object using times and states:

td = TemporalData[states, {times}];

Using ListPlot:

ListPlot[td, PlotLegends ->labels, ImageSize -> 500]

enter image description here

Alternatives:

ListPlot[Transpose@states, DataRange -> Through@{Min, Max}@times, 
 PlotLegends -> labels, ImageSize -> 500]
(* same picture *)

Or, create six series of {date, value} pairs:

datab = Rest[Rest /@ data][[All, {1, #}]] & /@ Range[2, 7];
ListPlot[datab, PlotLegends -> labels, ImageSize -> 500]
(* also same picture *)

Using DateListPlot:

DateListPlot[Transpose@states, {Min@times}, PlotLegends -> labels, ImageSize -> 500]

enter image description here

Alternatively, turn {date, value} pairs in datab into {{date}, value} pairs:

datac = datab;
datac[[All, All, 1]] = List /@ # & /@ datab[[All, All, 1]];
DateListPlot[datac, PlotLegends -> labels, ImageSize -> 500]
(* same picture *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.