Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I want to do is to compare the relationship between the consumption of say beer and wine using scatter plots where each point designates the particular country (preferably named). I have tried to part the information - so that each particular column becomes a vector - using the function Part without any success. I find this bewildering given that Dimension[data] yields the result {19,4}.

For those of you that are familiar with R: What I would like to do to is to part the information, like this

    > Country <-data$Country
    > Beer <-data$Beer
    > Wine <-data$Wine
    > HardLiquid <-data$HardLiquid

and then produce scatter plots which names every country.

> plot(Beer,Wine,type="n")
> text(Beer,Wine,Country)


This is the data that I am working on in Mathematica:

data = {{"Country", "Beer", "Wine", "Hard Liquid"}, 
 {"Sweden", 56., 16., 2.9}, 
 {"Danmark", 98., 32., 2.7}, 
 {"Finland", 79., 10., 5.7}, 
 {"Norway", 56., 11., 2.4}, 
 {"Belgium", 98., 30., 2.6},
 {"France", 47., 41., 7.2}, 
 {"Irland", 155., 13., 5.3}, 
 {"Italy", 29., 54., 2.7}, 
 {"Netherlands", 80., 20., 4.7}, 
 {"Switzerland", 57., 42., 2.4}, 
 {"Kingdom United", 20., 97., 3.9}, 
 {"Germany", 26., 119., 5.3}, 
 {"Austria", 36., 106., 3.2}, 
 {"USA", 85., 7., 4.8}, 
 {"Canada", 70., 10., 4.3}, 
 {"Australia", 21., 89., 2.6}, 
 {"Nya Zeeland", 19., 78., 2.3}, 
 {"Japan", 55., 10., 8.2}}
share|improve this question
I honestly don't know, I simply copied the cell. – user12779 Mar 5 '14 at 12:22
ListPlot[Tooltip[{#2, #3}, #] & @@@ data[[ 2 ;;]], AxesLabel -> {"Beer", "Wine"}]? – Kuba Mar 5 '14 at 12:27
Are you sure you are using Part right? You say "I tried to part the information using Part", which sounds curious to me. Note that the main use of Part is not to part something into multiple parts, but rather to get a part of the expression. In your case data[[2;; ,2]]] should give you a list of the values in the beer consumption column. But see also Kuba's code, which shows that you can skip getting the columns altogether. – Jacob Akkerboom Mar 5 '14 at 12:34
I encounter the following message when when I use Kuba's code: "ListPlot::lpn : TableForm[] is not a list of numbers or pairs of numbers". As for the second question; I apparently don't seem to use it correctly. After all, I don't obtain the desired outcome. Nevertheless, I have tried the same argument in other instance and been successful, which is to say I have managed to isolate the columns without any error messages. As I have stated above; I find this bewildering. – user12779 Mar 5 '14 at 12:42
@user12779 it appears you are dealing with a hidden wrapper TableForm around your data. You can use FullForm to see if it is present, or perhaps you can see what Head[data] is. If it is TableForm, try to find out where you add TableForm and undo this. – Jacob Akkerboom Mar 5 '14 at 12:46
up vote 2 down vote accepted
f = DynamicModule[{col = Black}, 
   DynamicWrapper[Dynamic@Style[#, col], 
                  If[CurrentValue["MouseOver"], col = Red; pos = {#2, #3}, 
                                                col = Black; pos = {}]]] &;

With[{d1 = Rest@data}, 
     ListPlot[{{#2, #3}} & @@@ d1, BaseStyle -> {PointSize@.02, 15, Bold}, 
                                   AspectRatio -> Automatic,
              Epilog -> {Inset[Grid@Partition[f @@@ d1, 2], Scaled@{.7, .6}], 
                         Thick, PointSize@.05, Opacity@.5, Dynamic@Point[pos]},
              PlotRangePadding -> {Automatic, {Automatic, Scaled@.5}}]]

enter image description here

share|improve this answer
thank you for introducing me to DynamicWrapper and its joys +1 seems to small...:) – ubpdqn Mar 6 '14 at 13:13
@ubpdqn I'm glad you like it :) I'm not sure if DynamicWrapper is the best choice here but the more diversity in answers the more we all are learning :) – Kuba Mar 6 '14 at 13:15
Same here @Kuba, first time to see this function. – Zviovich Mar 6 '14 at 13:29
That is absolutely wonderful! Thanks Kuba! – user12779 Mar 7 '14 at 10:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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