-1
$\begingroup$

With the following Code, I generate various ListLinePlots but I like to create the example figure given below:

ClearAll[data, time];
SeedRandom[21];
data = RandomReal[{1, 100}, {24, 12}];
time = Transpose@{{2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021}};
data1 = PrependTo[data, time // Flatten] // Transpose;
plot1 = ListLinePlot[Transpose[data1][[{2, 3}]], PlotLegends -> {2, 3}];
plot2 = ListLinePlot[Transpose[data1][[{4, 5}]], PlotLegends -> {4, 5}];
plot3 = ListLinePlot[Transpose[data1][[{6, 7}]], PlotLegends -> {6, 7}];
plot4 = ListLinePlot[Transpose[data1][[{8, 9}]], PlotLegends -> {8, 9}];
Row[{plot1, plot2, plot3, plot4}]

In the data matrix data1 the first column is X-axis denoting time (2010, 2011,...,2021) and is common for all countries. For simplicity, the data in the 2nd and 3rd columns represent country 1 for two time-series variables; and the 4th and 5th columns, country 2; etc. I have 12 countries consistent with the data given. There are two labels: blue and orange with names Label 1 and Label 2 as in the example.

This is the plot I like to produce:

enter image description here

$\endgroup$
4
  • 2
    $\begingroup$ See ResourceFunction["PlotGrid"] $\endgroup$
    – Bob Hanlon
    Oct 9, 2021 at 14:03
  • $\begingroup$ @BobHanlon: Grid is not really creating the type of plot shown in the example. Thanks $\endgroup$ Oct 9, 2021 at 14:19
  • 3
    $\begingroup$ Tugrul, but have you investigated the linked resource function? I am guessing it can be used for such thing as the plot type you want, by simply removing some of the vertical axes/frame edges. Investigating this method should turn fruitful for you. $\endgroup$ Oct 9, 2021 at 15:10
  • 1
    $\begingroup$ @CA Trevillian: I did examine it and tried few things. My problem is to create a single X-axis for a group of countries over a fixed time period. This is where I got stuck. $\endgroup$ Oct 9, 2021 at 15:34

1 Answer 1

3
$\begingroup$
ClearAll[data, time];
SeedRandom[21];
data = RandomReal[{1, 100}, {24, 12}];
time = Transpose@{{2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 
     2018, 2019, 2020, 2021}};
data1 = PrependTo[data, time // Flatten] // Transpose;

plot[n_] := Labeled[
  ListLinePlot[
   Transpose[data1][[{2 n, 2 n + 1}]],
   PlotLegends -> Placed[{2 n, 2 n + 1}, Above],
   Ticks -> {{1, 12}, Automatic},
   Axes -> If[n == 1, True, {True, False}],
   PlotRangePadding ->
    {{0, Scaled[0.05]}, Automatic}],
  StringForm["Plot ``", n], Below]

ResourceFunction["PlotGrid"][{plot /@ Range[4]}]

enter image description here

$\endgroup$

Your Answer

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

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