I have seen several conditional plotting as well as grouped data questions (e.g. here and here) but my problem is different. I have following sample data dat
in my R dataframe
. The data contains five columns, i.e., Grp (character)
, Var (integer)
(unequal rows for each group), Col1 (numeric)
, Col2 (numeric)
, Col3 (numeric)
.
Grp Var Col1 Col2 Col3
grp_1 8 46.8 50.0 50.6
grp_1 16 95.6 47.4 48.0
grp_1 24 45.1 45.6 46.4
grp_1 32 68.8 44.3 58.2
grp_1 40 44.6 52.2 44.3
grp_1 48 86.5 42.2 68.6
grp_2 40 63.2 95.6 63.0
grp_2 60 66.7 67.5 65.6
grp_2 80 69.6 70.7 67.9
grp_2 100 71.9 73.4 69.3
grp_2 120 73.8 75.7 48.0
grp_3 500 51.9 50.0 50.5
grp_3 1000 65.5 53.0 53.4
grp_3 5000 61.2 99.0 59.9
grp_3 10000 80.1 63.0 62.8
grp_3 30000 25.9 33.8 14.2
For each group, I would like to plot columns Col1
, Col2
, Col3
(y-axis) against Var
(x-axis), and conditionally change x-axis title as "steps", "number1", and "number2" for Var
values corresponding to grp_1,
grp_2
and grp_3.
I see a relevant question on conditionally changing labels for two variables here but couldn't find for three variables. I need to plot above data for several groups (both in individual plots written to local disk and grid of 4 plots) so I am looking for suggestions on loop
and/or function
approaches. Can somebody suggest on how this could be achieved?