2
$\begingroup$

I have data regional data listed by country in this form:

data = {{{"Reg1", "Country1", 5}, {"Reg1", "Country2", 6}}, {{"Reg2", 
     "Country3", 2}, {"Reg2", "Country4", 3}, {"Reg2", "Country5", 
     3}}};

I want to plot all the country values in each region on a single x-value, such as I have, in the example, two x values.

So far I can only plot as follows in which in absence of y values ListPlot assigns consecutive x values to each data point.

ListPlot[data[[1 ;; 2, ;; , 3]]]

enter image description here

I would like it to look like this:

enter image description here

My original dataset is huge so I need it to be programmed and I have more than 3 columns, I have values per country for several years which I'd like to plot on separate graphs.

$\endgroup$
3
$\begingroup$
Table[{i, #} & /@ (data[[i, ;; , 3]]), {i, 2}] // ListPlot

produces what you request:

enter image description here

$\endgroup$
0
$\begingroup$
cords=MapIndexed[{First@#2, Last@#1} &, data, {2}]
ListPlot[coords]
$\endgroup$
1
$\begingroup$

Another possibility:

Thread /@ Transpose[{Range[Length@data], data[[All, All, -1]]}] // ListPlot
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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