2
$\begingroup$

I need to plot a dataset with the x-axis ticks as character (String) instead of conventional number. How can I do it? Here is my data and code:

data={{"V", 61.5969, 33.626}, {"Y", 56.9077, 39.7866}, {"P", 62.9692, 
     31.8801}, {"V", 61.6344, 33.466}, {"D", 53.2597, 42.799}, {"L", 
     54.199, 42.8786}, {"S", 56.8791, 65.2661}, {"K", 54.5083, 
     35.1462}, {"V", 61.5614, 32.4005}, {"T", 61.4146, 71.286}, {"S", 
     57.6121, 65.6026}, {"K", 55.2787, 34.7415}, {"C", 56.9249, 
     30.3367}, {"G", 46.4798, 0}, {"S", 58.0113, 64.6901}, {"G", 45.4069,
     0}, {"N", 53.8871, 37.5137}, {"I", 60.7843, 39.2903}, {"E", 55.043,
     32.5105}, {"V", 60.7334, 34.5962}, {"K", 55.5029, 34.9302}, {"S", 
     57.475, 65.4979}, {"E", 57.3842, 30.8813}, {"R", 57.1591, 
     28.1642}, {"V", 63.0286, 32.2004}, {"Q", 54.774, 30.6936}, {"S", 
     56.898, 65.386}, {"K", 55.3617, 34.8906}, {"I", 60.4146, 
     40.4549}, {"G", 46.0692, 0}, {"S", 58.2961, 64.0659}, {"L", 53.904, 
     42.2776}};
 xticks = data[[All, 1]];
 ListLinePlot[Transpose[{Table[i, {i, 1, 37}], data[[All, 2]]}], 
    Axes -> False, Frame -> True, AspectRatio -> 0.4, ImageSize -> 750, FrameTicks -> {{{45, 50, 55, 60}, None}, {xticks, None}}]

But in the plot, no tick appears. Any suggestion will be really helpful. I am using Mathematica 12.

$\endgroup$

1 Answer 1

3
$\begingroup$

Define xticks as

xticks = Thread[{Range@Length@data, data[[All, 1]]}];

enter image description here

Note: Replaced Table[i, {i, 1, 37}] with Table[i, {i, 1, Length@data}]

See: Ticks > Details

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.