Hello Stata List forum members,
I am creating a two-way line graph in STATA 17.0 using a continuous variable on the y-axis and a coded categorical variable on the x-axis. I am having trouble with the spacing on the x-axis where the ticks are not evenly spaced and I can't seem to find a way to make them even. Would anyone be able to help with this? This is the code I am using:
I have attached an image of the graph and here is sample data to use:
In the graph, I am also unsure why some of the data lines have breaks in the lines, they should be connected for each ID_visit - can anyone see why there would be a problem with this?
Thank you in advance for your help.
I am creating a two-way line graph in STATA 17.0 using a continuous variable on the y-axis and a coded categorical variable on the x-axis. I am having trouble with the spacing on the x-axis where the ticks are not evenly spaced and I can't seem to find a way to make them even. Would anyone be able to help with this? This is the code I am using:
Code:
drop if Objective!="B2a" drop if NfL==. local B2bNfLylab="0(20)100" local axislabelformat labsize(medium) tlwidth(medthick) angle(0) local B2axlab = "5 6 12 13" local B2axaxis xlabel(5 "0d" 6 "3d" 12 "0d" 13 "3d") local B2aNfLy="0 70" local axislabelformat labsize(medium) tlwidth(medthick) angle(0) twoway (line NfL sample_delay1 if disease_grp==0, c(L) lcolor("`INF_grey'")) /// (line NfL sample_delay1 if disease_grp==1, c(L) lcolor("`INF_gold'")) /// (line NfL sample_delay1 if disease_grp==2, c(L) lcolor("`INF_Red'")), /// ylabel(`B2aNfLylab', `axislabelformat') /// xlabel(`B2axlab', valuelabel `axislabelformat') /// `B2axaxis' /// yscale(range(`B2aNfLy')) /// legend(off) ytitle("NfL pg/mL") xtitle("Sample delay") /// `axislineformat' /// name(practice_Spag,replace) gr_edit .plotregion1.style.editstyle boxstyle(linestyle(color(none))) editcopy
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str5 Objective double NfL str7 ID_visit float process_delay str7 sample_delay long sample_delay1 float disease_grp "B2a" 6.78976348216652 "019_002" 0 "Ven_S_0" 12 0 "B2a" 6.05453975047093 "019_002" 3 "Ven_S_3" 13 0 "B2a" 6.43117929188989 "019_002" 0 "Cap_S_0" 5 0 "B2a" 7.77724284703385 "019_002" 3 "Cap_S_3" 6 0 "B2a" 46.0262954338041 "023_000" 0 "Ven_S_0" 12 2 "B2a" 45.3400963334667 "023_000" 3 "Ven_S_3" 13 2 "B2a" 42.1146407423491 "023_000" 0 "Cap_S_0" 5 2 "B2a" 44.5097361884643 "023_000" 3 "Cap_S_3" 6 2 "B2a" 6.50151907855725 "034_002" 0 "Ven_S_0" 12 0 "B2a" 6.69151993456443 "034_002" 3 "Ven_S_3" 13 0 "B2a" 6.6533028955191 "034_002" 0 "Cap_S_0" 5 0 "B2a" 6.70771212362222 "034_002" 3 "Cap_S_3" 6 0 "B2a" 6.10433716670134 "035_001" 0 "Ven_S_0" 12 0 "B2a" 5.7426620129731 "035_001" 3 "Ven_S_3" 13 0 "B2a" 6.40042989719446 "035_001" 0 "Cap_S_0" 5 0 "B2a" 7.40253128905567 "035_001" 3 "Cap_S_3" 6 0 "B2a" 17.0881359385239 "039_000" 0 "Ven_S_0" 12 1 "B2a" 17.5497884659482 "039_000" 3 "Ven_S_3" 13 1 "B2a" 15.1326740035172 "039_000" 0 "Cap_S_0" 5 1 "B2a" 17.6452026407081 "039_000" 3 "Cap_S_3" 6 1 "B2a" 14.5800076367392 "040_000" 0 "Ven_S_0" 12 1 "B2a" 15.1644764097372 "040_000" 3 "Ven_S_3" 13 1 "B2a" 14.5638184570952 "040_000" 0 "Cap_S_0" 5 1 "B2a" 17.5479438185644 "040_000" 3 "Cap_S_3" 6 1 "B2a" 16.0990814088212 "042_000" 0 "Ven_S_0" 12 1 "B2a" 15.9458315219729 "042_000" 3 "Ven_S_3" 13 1 "B2a" 15.3864839671494 "042_000" 0 "Cap_S_0" 5 1 "B2a" 15.0329304453604 "042_000" 3 "Cap_S_3" 6 1 "B2a" 38.8828240890249 "048_000" 0 "Ven_S_0" 12 1 "B2a" 42.7880049447568 "048_000" 3 "Ven_S_3" 13 1 "B2a" 35.0047203335076 "048_000" 0 "Cap_S_0" 5 1 "B2a" 39.1660922425035 "048_000" 3 "Cap_S_3" 6 1 "B2a" 19.2651316050738 "050_000" 0 "Ven_S_0" 12 1 "B2a" 20.4256461574558 "050_000" 3 "Ven_S_3" 13 1 "B2a" 17.5064017366281 "050_000" 0 "Cap_S_0" 5 1 "B2a" 19.7032597838733 "050_000" 3 "Cap_S_3" 6 1 "B2a" 17.4070376465001 "054_000" 0 "Ven_S_0" 12 0 "B2a" 17.7275810869912 "054_000" 3 "Ven_S_3" 13 0 "B2a" 15.9835372637685 "054_000" 0 "Cap_S_0" 5 0 "B2a" 16.3277934086917 "054_000" 3 "Cap_S_3" 6 0 "B2a" 45.221089826051 "055_000" 0 "Ven_S_0" 12 2 "B2a" 46.9620374658654 "055_000" 3 "Ven_S_3" 13 2 "B2a" 47.770735349467 "055_000" 0 "Cap_S_0" 5 2 "B2a" 48.6682827654008 "055_000" 3 "Cap_S_3" 6 2 "B2a" 17.2000014535273 "056_000" 0 "Ven_S_0" 12 0 "B2a" 17.5059862305317 "056_000" 3 "Ven_S_3" 13 0 "B2a" 16.2012062130292 "056_000" 0 "Cap_S_0" 5 0 "B2a" 17.3096523454328 "056_000" 3 "Cap_S_3" 6 0 "B2a" 66.5034806350149 "057_000" 0 "Ven_S_0" 12 2 "B2a" 68.8328046878072 "057_000" 3 "Ven_S_3" 13 2 "B2a" 58.9675373743417 "057_000" 0 "Cap_S_0" 5 2 "B2a" 58.4941986859436 "057_000" 3 "Cap_S_3" 6 2 "B2a" 40.7057150501344 "058_000" 0 "Ven_S_0" 12 2 "B2a" 45.7902819263404 "058_000" 3 "Ven_S_3" 13 2 "B2a" 40.8156966385452 "058_000" 0 "Cap_S_0" 5 2 "B2a" 40.2456975017882 "058_000" 3 "Cap_S_3" 6 2 "B2a" 28.4304298836526 "060_000" 0 "Ven_S_0" 12 2 "B2a" 29.8003511730568 "060_000" 3 "Ven_S_3" 13 2 "B2a" 26.3127097283489 "060_000" 0 "Cap_S_0" 5 2 "B2a" 26.8758220956767 "060_000" 3 "Cap_S_3" 6 2 "B2a" 16.7480572229323 "061_000" 0 "Ven_S_0" 12 0 "B2a" 19.4205510531086 "061_000" 3 "Ven_S_3" 13 0 "B2a" 18.0594905682777 "061_000" 0 "Cap_S_0" 5 0 "B2a" 18.1681549556479 "061_000" 3 "Cap_S_3" 6 0 "B2a" 5.79983039306694 "062_000" 0 "Ven_S_0" 12 0 "B2a" 5.6427251195098 "062_000" 3 "Ven_S_3" 13 0 "B2a" 5.9606477518031 "062_000" 0 "Cap_S_0" 5 0 "B2a" 5.77776693593664 "062_000" 3 "Cap_S_3" 6 0 "B2a" 13.9201886666513 "063_000" 0 "Ven_S_0" 12 0 "B2a" 11.6334913176376 "063_000" 3 "Ven_S_3" 13 0 "B2a" 12.0943081676757 "063_000" 0 "Cap_S_0" 5 0 "B2a" 13.3670843384248 "063_000" 3 "Cap_S_3" 6 0 "B2a" 7.06439821908379 "064_000" 0 "Ven_S_0" 12 0 "B2a" 8.5743497169679 "064_000" 3 "Ven_S_3" 13 0 "B2a" 7.83106699654396 "064_000" 0 "Cap_S_0" 5 0 "B2a" 8.1415417713203 "064_000" 3 "Cap_S_3" 6 0 "B2a" 6.2413575708949 "065_000" 0 "Ven_S_0" 12 0 "B2a" 5.42715192652326 "065_000" 3 "Ven_S_3" 13 0 "B2a" 7.52413292798331 "065_000" 0 "Cap_S_0" 5 0 "B2a" 7.55295331786773 "065_000" 3 "Cap_S_3" 6 0 end label values process_delay delay label def delay 0 "No delay", modify label def delay 3 "3-day delay", modify label values sample_delay1 sample_delay1 label def sample_delay1 5 "Cap_S_0", modify label def sample_delay1 6 "Cap_S_3", modify label def sample_delay1 12 "Ven_S_0", modify label def sample_delay1 13 "Ven_S_3", modify label values disease_grp status label def status 0 "Controls", modify label def status 1 "PreHD", modify label def status 2 "Manifest HD", modify
In the graph, I am also unsure why some of the data lines have breaks in the lines, they should be connected for each ID_visit - can anyone see why there would be a problem with this?
Thank you in advance for your help.
Comment