Mathematica Asked by Stuart Poss on December 10, 2020
From a previous question and with the help of kglr a grid containing a data matrix with column labels was properly formatted and created
Controlling label alignment/spacing in large grids
Having this grid in hand, I would like to generate a new grid that includes row labels, but have discovered I still do not fully understand how to successfully use the Part, Style and Join Functions in this context. I’ve tried to follow several answers in several previous questions regarding grid labeling, but can not seem to create the proper syntax to add the newly styled row labels to the previous grid. Note that the fonts in the original grid are not italicized, whereas those in the labels are using FontSlant->Italic. Note also that the column spacing and the rotated column labels of the original grid need to be retained in the final grid.
For purposes of example and to match the grid in the previous post I use the following set of row labels:
mspecies = {" ", "Synanceia verrucosa", "Pterois volitans", "Pterois miles",
"Helicolenus avius", "Helicolenus hilgendorfi","Sebastes aleutianus", "Sebastes fasciatus",
"Sebastes koreanus","Sebastes trivittatus"}
That I have styled using:
mspecies2 =
Style[mspecies, FontFamily -> "Helvetica", FontSize -> 8,
FontWeight -> Bold, FontSlant -> Italic]
which I would like to appear as row labels in the new grid.
Is there a way to effectively Preappend this list of row labels suitably formatted to the original grid to form a new grid retaining both the content and formatting of the original data and labels but including the new properly styled row labels?
You can map Style
on elements of mspecies
:
mspecies2 = Style[#, FontFamily -> "Helvetica", FontSize -> 8,
FontWeight -> Bold, FontSlant -> Italic] & /@ mspecies;
Use the method in the linked q/a to get a 9X20 grid with rotated column headers:
n = 20;
result = Join[ConstantArray["A", {5, n}], ConstantArray["T", {4, n}]];
columnlabels = Range[Last[Dimensions[result]]];
newcolumnlabels = Rotate[StringTake["00000" <> ToString[#], -5], [Pi]/2] & /@
columnlabels;
Prepend each row with its styled row header:
datawithheaders = MapThread[Prepend, {Prepend[result, newcolumnlabels], mspecies2}];
Style[Grid[datawithheaders,
Frame -> All, Alignment -> {Center, Center}], FontSize -> 8,
LineBreakWithin -> False]
Use Alignment -> {Center, Center, {1 -> Left}}
to get
Answered by kglr on December 10, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP