Splitting a facet wrap into two additional facets - r

I am using the following to plot some data, however on the full sample the data is a little difficult to see since I have too many variables on the same plot. How can I split each of the facets into 2? That is, have the first half of the variables plotted on one line and the second half of the variables plotted on the second line but keep each of the current 4 facets?.
ggplot code removed due to character limit
Data:
structure(list(Status = structure(c(2L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L,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 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c("0",
"1"), class = "factor"), Model = c("2", "3", "2", "2", "2", "4",
"2", "3", "3", "2", "1", "4", "3", "1", "4", "3", "3", "3", "2",
"1", "2", "1", "2", "3", "3", "3", "3", "4", "3", "2", "1", "3",
"1", "2", "1", "1", "4", "2", "2", "4", "4", "2", "2", "1", "4",
"1", "2", "2", "3", "2", "4", "3", "3", "3", "2", "3", "2", "3",
"4", "1", "2", "3", "2", "2", "3", "4", "2", "3", "1", "1", "3",
"4", "4", "4", "2", "1", "2", "3", "4", "3", "2", "4", "1", "1",
"1", "2", "2", "2", "4", "3", "1", "4", "3", "2", "2", "4", "1",
"4", "1", "1", "3", "4", "2", "3", "3", "3", "4", "3", "3", "3",
"2", "4", "1", "2", "4", "1", "4", "3", "2", "2", "4", "2", "4",
"4", "4", "4", "4", "1", "4", "1", "1", "2", "3", "3", "4", "1",
"4", "3", "3", "1", "3", "1", "1", "3", "1", "4", "3", "1", "4",
"4", "2", "2", "4", "1", "1", "2", "2", "4", "1", "1", "2", "2",
"3", "3", "2", "1", "3", "3", "4", "3", "1", "4", "2", "4", "3",
"4", "4", "3", "2", "2", "3", "1", "1", "1", "4", "3", "4", "3",
"2", "1", "3", "1", "4", "3", "4", "3", "2", "3", "3", "3", "3",
"1", "4", "1", "1", "3", "3", "4", "1", "1", "3", "4", "2", "1",
"4", "4", "1", "4", "4", "2", "1", "3", "2", "1", "3", "2", "2",
"1", "1", "4", "1", "4", "2", "2", "4", "1", "3", "3", "2", "4",
"3", "1", "2", "3", "1", "4", "3", "1", "2", "4", "2", "3", "1",
"4", "1", "3", "1", "4", "1", "4", "1", "3", "4", "1", "2", "3",
"4", "3", "2", "4", "3", "2", "2", "1", "2", "2", "1", "4", "2",
"4", "3", "2", "1", "1", "3", "3", "3", "4", "4", "4", "3", "4",
"4", "2", "1", "4", "1", "3", "1", "2", "1", "4", "3", "1", "3",
"4", "1", "1", "4", "4", "1", "3", "4", "1", "1", "1", "1", "4",
"4", "2", "4", "3", "1", "4", "1", "2", "4", "1", "4", "2", "2",
"3", "4", "2", "4", "4", "4", "3", "4", "4", "1", "3", "3", "2",
"4", "4", "1", "1", "2", "2", "2", "3", "3", "4", "3", "2", "4",
"4", "4", "1", "2", "4", "4", "4", "3", "2", "2", "3", "4", "1",
"3", "1", "4", "1", "3", "2", "3", "3", "3", "4", "3", "1", "4",
"4", "4", "1", "3", "3", "1", "1", "1", "3", "2", "4", "4", "3",
"3", "3", "2", "2", "1", "3", "1", "4", "1", "4", "3", "1", "2",
"3", "3", "1", "2", "4", "4", "2", "2", "4", "3", "1", "1", "4",
"2", "4", "2", "2", "1", "3", "4", "3", "4", "3", "2", "3", "2",
"4", "2", "1", "1", "4", "3", "3", "4", "4", "4", "4", "1", "1",
"2", "4", "4", "2", "3", "3", "2", "2", "3", "4", "4", "1", "2",
"1", "1", "2", "2", "1", "2", "3", "3", "4", "1", "3", "4", "1",
"4", "1", "2", "3", "2", "3", "2", "4", "2", "1", "4", "3", "1",
"2", "3", "3", "2", "2", "4", "4", "1", "4", "4", "3", "1", "3"
), Model_Name = c("2 Year", "3 Year", "2 Year", "2 Year", "2 Year",
"4 Year", "2 Year", "3 Year", "3 Year", "2 Year", "1 Year", "4 Year",
"3 Year", "1 Year", "4 Year", "3 Year", "3 Year", "3 Year", "2 Year",
"1 Year", "2 Year", "1 Year", "2 Year", "3 Year", "3 Year", "3 Year",
"3 Year", "4 Year", "3 Year", "2 Year", "1 Year", "3 Year", "1 Year",
"2 Year", "1 Year", "1 Year", "4 Year", "2 Year", "2 Year", "4 Year",
"4 Year", "2 Year", "2 Year", "1 Year", "4 Year", "1 Year", "2 Year",
"2 Year", "3 Year", "2 Year", "4 Year", "3 Year", "3 Year", "3 Year",
"2 Year", "3 Year", "2 Year", "3 Year", "4 Year", "1 Year", "2 Year",
"3 Year", "2 Year", "2 Year", "3 Year", "4 Year", "2 Year", "3 Year",
"1 Year", "1 Year", "3 Year", "4 Year", "4 Year", "4 Year", "2 Year",
"1 Year", "2 Year", "3 Year", "4 Year", "3 Year", "2 Year", "4 Year",
"1 Year", "1 Year", "1 Year", "2 Year", "2 Year", "2 Year", "4 Year",
"3 Year", "1 Year", "4 Year", "3 Year", "2 Year", "2 Year", "4 Year",
"1 Year", "4 Year", "1 Year", "1 Year", "3 Year", "4 Year", "2 Year",
"3 Year", "3 Year", "3 Year", "4 Year", "3 Year", "3 Year", "3 Year",
"2 Year", "4 Year", "1 Year", "2 Year", "4 Year", "1 Year", "4 Year",
"3 Year", "2 Year", "2 Year", "4 Year", "2 Year", "4 Year", "4 Year",
"4 Year", "4 Year", "4 Year", "1 Year", "4 Year", "1 Year", "1 Year",
"2 Year", "3 Year", "3 Year", "4 Year", "1 Year", "4 Year", "3 Year",
"3 Year", "1 Year", "3 Year", "1 Year", "1 Year", "3 Year", "1 Year",
"4 Year", "3 Year", "1 Year", "4 Year", "4 Year", "2 Year", "2 Year",
"4 Year", "1 Year", "1 Year", "2 Year", "2 Year", "4 Year", "1 Year",
"1 Year", "2 Year", "2 Year", "3 Year", "3 Year", "2 Year", "1 Year",
"3 Year", "3 Year", "4 Year", "3 Year", "1 Year", "4 Year", "2 Year",
"4 Year", "3 Year", "4 Year", "4 Year", "3 Year", "2 Year", "2 Year",
"3 Year", "1 Year", "1 Year", "1 Year", "4 Year", "3 Year", "4 Year",
"3 Year", "2 Year", "1 Year", "3 Year", "1 Year", "4 Year", "3 Year",
"4 Year", "3 Year", "2 Year", "3 Year", "3 Year", "3 Year", "3 Year",
"1 Year", "4 Year", "1 Year", "1 Year", "3 Year", "3 Year", "4 Year",
"1 Year", "1 Year", "3 Year", "4 Year", "2 Year", "1 Year", "4 Year",
"4 Year", "1 Year", "4 Year", "4 Year", "2 Year", "1 Year", "3 Year",
"2 Year", "1 Year", "3 Year", "2 Year", "2 Year", "1 Year", "1 Year",
"4 Year", "1 Year", "4 Year", "2 Year", "2 Year", "4 Year", "1 Year",
"3 Year", "3 Year", "2 Year", "4 Year", "3 Year", "1 Year", "2 Year",
"3 Year", "1 Year", "4 Year", "3 Year", "1 Year", "2 Year", "4 Year",
"2 Year", "3 Year", "1 Year", "4 Year", "1 Year", "3 Year", "1 Year",
"4 Year", "1 Year", "4 Year", "1 Year", "3 Year", "4 Year", "1 Year",
"2 Year", "3 Year", "4 Year", "3 Year", "2 Year", "4 Year", "3 Year",
"2 Year", "2 Year", "1 Year", "2 Year", "2 Year", "1 Year", "4 Year",
"2 Year", "4 Year", "3 Year", "2 Year", "1 Year", "1 Year", "3 Year",
"3 Year", "3 Year", "4 Year", "4 Year", "4 Year", "3 Year", "4 Year",
"4 Year", "2 Year", "1 Year", "4 Year", "1 Year", "3 Year", "1 Year",
"2 Year", "1 Year", "4 Year", "3 Year", "1 Year", "3 Year", "4 Year",
"1 Year", "1 Year", "4 Year", "4 Year", "1 Year", "3 Year", "4 Year",
"1 Year", "1 Year", "1 Year", "1 Year", "4 Year", "4 Year", "2 Year",
"4 Year", "3 Year", "1 Year", "4 Year", "1 Year", "2 Year", "4 Year",
"1 Year", "4 Year", "2 Year", "2 Year", "3 Year", "4 Year", "2 Year",
"4 Year", "4 Year", "4 Year", "3 Year", "4 Year", "4 Year", "1 Year",
"3 Year", "3 Year", "2 Year", "4 Year", "4 Year", "1 Year", "1 Year",
"2 Year", "2 Year", "2 Year", "3 Year", "3 Year", "4 Year", "3 Year",
"2 Year", "4 Year", "4 Year", "4 Year", "1 Year", "2 Year", "4 Year",
"4 Year", "4 Year", "3 Year", "2 Year", "2 Year", "3 Year", "4 Year",
"1 Year", "3 Year", "1 Year", "4 Year", "1 Year", "3 Year", "2 Year",
"3 Year", "3 Year", "3 Year", "4 Year", "3 Year", "1 Year", "4 Year",
"4 Year", "4 Year", "1 Year", "3 Year", "3 Year", "1 Year", "1 Year",
"1 Year", "3 Year", "2 Year", "4 Year", "4 Year", "3 Year", "3 Year",
"3 Year", "2 Year", "2 Year", "1 Year", "3 Year", "1 Year", "4 Year",
"1 Year", "4 Year", "3 Year", "1 Year", "2 Year", "3 Year", "3 Year",
"1 Year", "2 Year", "4 Year", "4 Year", "2 Year", "2 Year", "4 Year",
"3 Year", "1 Year", "1 Year", "4 Year", "2 Year", "4 Year", "2 Year",
"2 Year", "1 Year", "3 Year", "4 Year", "3 Year", "4 Year", "3 Year",
"2 Year", "3 Year", "2 Year", "4 Year", "2 Year", "1 Year", "1 Year",
"4 Year", "3 Year", "3 Year", "4 Year", "4 Year", "4 Year", "4 Year",
"1 Year", "1 Year", "2 Year", "4 Year", "4 Year", "2 Year", "3 Year",
"3 Year", "2 Year", "2 Year", "3 Year", "4 Year", "4 Year", "1 Year",
"2 Year", "1 Year", "1 Year", "2 Year", "2 Year", "1 Year", "2 Year",
"3 Year", "3 Year", "4 Year", "1 Year", "3 Year", "4 Year", "1 Year",
"4 Year", "1 Year", "2 Year", "3 Year", "2 Year", "3 Year", "2 Year",
"4 Year", "2 Year", "1 Year", "4 Year", "3 Year", "1 Year", "2 Year",
"3 Year", "3 Year", "2 Year", "2 Year", "4 Year", "4 Year", "1 Year",
"4 Year", "4 Year", "3 Year", "1 Year", "3 Year"), status = c(1L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0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L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L), Feature = c("CF.CL", "CF.SALES", "TL.TA", "logSALES",
"TL.EQ", "TL.EQ", "CF.SALES", "CF.SALES", "CL.FinExp", "CF.CL",
"TL.EQ", "EBIT.Capital", "DEBTORS.SALES", "CF.SALES", "EBIT.FinExp",
"EQ.Turnover", "WC.EBIT", "logTA", "CA.CL", "CF.SALES", "CF.NCL",
"EBIT.FinExp", "EQ.Turnover", "SALES.FA", "SALES.FA", "EBITDA.SALES",
"EBITDA.SALES", "CL.FinExp", "logTA", "CF.CL", "SALES.EBIT",
"DEBTORS.SALES", "WC.EBIT", "CF.NCL", "SALES.FA", "CF.NCL", "CA.CL",
"logSALES", "EBITDA.SALES", "TL.TA", "EBIT.FinExp", "EQ.Turnover",
"CF.SALES", "TL.EQ", "EQ.Turnover", "SALES.EBIT", "logTA", "EBIT.FinExp",
"logSALES", "EBIT.Capital", "EBIT.FinExp", "CF.CL", "SALES.EBIT",
"CF.NCL", "EBIT.FinExp", "SALES.FA", "TL.EQ", "EBITDA.SALES",
"logSALES", "WC.EBIT", "TL.TA", "TL.EQ", "EBIT.Capital", "logTA",
"logTA", "EBIT.Capital", "logSALES", "WC.EBIT", "logSALES", "TL.TA",
"EQ.Turnover", "CF.SALES", "logSALES", "EBIT.FinExp", "EBITDA.SALES",
"TL.EQ", "EBIT.Capital", "DEBTORS.SALES", "TL.TA", "EBIT.FinExp",
"SALES.FA", "DEBTORS.SALES", "CL.FinExp", "logTA", "EBIT.Capital",
"CF.NCL", "DEBTORS.SALES", "CF.SALES", "EBIT.Capital", "CA.CL",
"CF.NCL", "CF.SALES", "EBITDA.SALES", "EBIT.FinExp", "EBIT.Capital",
"DEBTORS.SALES", "EQ.Turnover", "TL.EQ", "TL.EQ", "CL.FinExp",
"EQ.Turnover", "logTA", "CF.SALES", "DEBTORS.SALES", "CF.CL",
"TL.TA", "CL.FinExp", "logTA", "CL.FinExp", "SALES.FA", "SALES.EBIT",
"SALES.EBIT", "EBITDA.SALES", "EBITDA.SALES", "WC.EBIT", "DEBTORS.SALES",
"DEBTORS.SALES", "DEBTORS.SALES", "EQ.Turnover", "WC.EBIT", "CL.FinExp",
"EQ.Turnover", "TL.TA", "CA.CL", "logSALES", "SALES.FA", "logTA",
"CL.FinExp", "CF.SALES", "logSALES", "EBITDA.SALES", "TL.TA",
"SALES.EBIT", "EBIT.FinExp", "EBIT.Capital", "CL.FinExp", "EQ.Turnover",
"SALES.FA", "logSALES", "CF.CL", "logTA", "CF.CL", "SALES.FA",
"logTA", "SALES.EBIT", "CL.FinExp", "WC.EBIT", "TL.EQ", "CL.FinExp",
"CL.FinExp", "EBITDA.SALES", "SALES.EBIT", "CF.CL", "DEBTORS.SALES",
"logTA", "logSALES", "TL.TA", "EQ.Turnover", "EQ.Turnover", "CL.FinExp",
"TL.TA", "EBIT.FinExp", "EBIT.Capital", "CF.SALES", "EBIT.FinExp",
"DEBTORS.SALES", "CL.FinExp", "CL.FinExp", "logSALES", "CA.CL",
"CF.CL", "SALES.FA", "DEBTORS.SALES", "CF.SALES", "CA.CL", "CL.FinExp",
"logTA", "SALES.FA", "DEBTORS.SALES", "SALES.FA", "EBITDA.SALES",
"EQ.Turnover", "EQ.Turnover", "logSALES", "EBIT.Capital", "CF.NCL",
"CA.CL", "logTA", "CF.SALES", "CF.CL", "DEBTORS.SALES", "SALES.EBIT",
"SALES.EBIT", "TL.EQ", "TL.EQ", "SALES.EBIT", "EBIT.FinExp",
"CF.SALES", "SALES.FA", "CL.FinExp", "WC.EBIT", "CF.NCL", "CL.FinExp",
"CF.CL", "logTA", "CF.SALES", "CA.CL", "logTA", "CF.CL", "EBIT.FinExp",
"CA.CL", "TL.EQ", "CF.CL", "logSALES", "TL.EQ", "EQ.Turnover",
"CL.FinExp", "SALES.FA", "EBIT.FinExp", "EBIT.Capital", "EQ.Turnover",
"CF.NCL", "CF.CL", "DEBTORS.SALES", "CL.FinExp", "TL.EQ", "CF.SALES",
"DEBTORS.SALES", "CL.FinExp", "CL.FinExp", "WC.EBIT", "EBIT.Capital",
"EBIT.Capital", "CA.CL", "EBITDA.SALES", "WC.EBIT", "EQ.Turnover",
"DEBTORS.SALES", "CL.FinExp", "CA.CL", "CF.NCL", "logSALES",
"DEBTORS.SALES", "WC.EBIT", "logSALES", "DEBTORS.SALES", "EBIT.Capital",
"DEBTORS.SALES", "CL.FinExp", "logSALES", "CA.CL", "WC.EBIT",
"CF.SALES", "TL.TA", "SALES.EBIT", "EBIT.FinExp", "SALES.FA",
"EBIT.FinExp", "WC.EBIT", "logTA", "DEBTORS.SALES", "TL.TA",
"CF.SALES", "EBIT.FinExp", "logSALES", "CF.SALES", "EBITDA.SALES",
"SALES.FA", "logSALES", "logSALES", "CF.CL", "CF.SALES", "CF.SALES",
"EBIT.Capital", "TL.TA", "EBIT.Capital", "CF.SALES", "SALES.FA",
"CF.CL", "TL.TA", "CL.FinExp", "TL.EQ", "CF.SALES", "CL.FinExp",
"logSALES", "DEBTORS.SALES", "CF.CL", "TL.EQ", "CA.CL", "DEBTORS.SALES",
"CA.CL", "SALES.FA", "SALES.EBIT", "SALES.FA", "logSALES", "TL.TA",
"logTA", "CA.CL", "CL.FinExp", "TL.TA", "CF.CL", "TL.EQ", "CF.NCL",
"WC.EBIT", "SALES.FA", "SALES.FA", "DEBTORS.SALES", "EBIT.Capital",
"EBITDA.SALES", "SALES.EBIT", "logSALES", "CF.NCL", "WC.EBIT",
"CL.FinExp", "EBIT.Capital", "CF.CL", "WC.EBIT", "SALES.FA",
"EBIT.FinExp", "CF.NCL", "WC.EBIT", "EBIT.FinExp", "SALES.FA",
"CF.SALES", "CF.NCL", "SALES.FA", "CL.FinExp", "CF.NCL", "TL.EQ",
"CA.CL", "logTA", "CL.FinExp", "DEBTORS.SALES", "CF.SALES", "CF.CL",
"TL.TA", "SALES.EBIT", "EQ.Turnover", "CA.CL", "SALES.FA", "CF.CL",
"EQ.Turnover", "CF.CL", "EBIT.Capital", "CL.FinExp", "CA.CL",
"DEBTORS.SALES", "EQ.Turnover", "CF.SALES", "CF.SALES", "TL.EQ",
"EBIT.Capital", "CF.SALES", "TL.TA", "WC.EBIT", "EQ.Turnover",
"WC.EBIT", "EBIT.Capital", "WC.EBIT", "logTA", "CF.SALES", "logTA",
"WC.EBIT", "CF.NCL", "SALES.FA", "WC.EBIT", "WC.EBIT", "EBIT.Capital",
"EQ.Turnover", "logTA", "SALES.EBIT", "TL.TA", "CF.NCL", "EBITDA.SALES",
"logSALES", "CL.FinExp", "SALES.EBIT", "TL.EQ", "DEBTORS.SALES",
"TL.EQ", "EQ.Turnover", "EBIT.Capital", "TL.EQ", "EBIT.FinExp",
"EBIT.FinExp", "CA.CL", "CL.FinExp", "TL.TA", "EBIT.Capital",
"logTA", "CL.FinExp", "CF.NCL", "CA.CL", "CL.FinExp", "EBITDA.SALES",
"CA.CL", "EQ.Turnover", "CL.FinExp", "SALES.EBIT", "CA.CL", "SALES.FA",
"TL.EQ", "EQ.Turnover", "EQ.Turnover", "EBITDA.SALES", "SALES.FA",
"logSALES", "SALES.EBIT", "EQ.Turnover", "WC.EBIT", "SALES.FA",
"EBIT.FinExp", "TL.TA", "DEBTORS.SALES", "SALES.EBIT", "WC.EBIT",
"logSALES", "EBIT.Capital", "WC.EBIT", "EQ.Turnover", "EBITDA.SALES",
"TL.EQ", "CF.CL", "EBIT.Capital", "CF.CL", "TL.EQ", "CF.NCL",
"WC.EBIT", "WC.EBIT", "EBITDA.SALES", "SALES.EBIT", "CF.NCL",
"CF.NCL", "CA.CL", "logSALES", "EBITDA.SALES", "EBIT.FinExp",
"SALES.EBIT", "TL.EQ", "CF.CL", "EBIT.Capital", "logTA", "EBITDA.SALES",
"EBIT.Capital", "TL.TA", "DEBTORS.SALES", "WC.EBIT", "DEBTORS.SALES",
"CF.SALES", "logTA", "SALES.EBIT", "EQ.Turnover", "CA.CL", "WC.EBIT",
"EBITDA.SALES", "EBITDA.SALES", "DEBTORS.SALES", "CA.CL", "EBIT.FinExp",
"EQ.Turnover", "DEBTORS.SALES", "CA.CL", "CF.NCL", "DEBTORS.SALES",
"logSALES", "CA.CL", "SALES.EBIT", "EBIT.Capital", "CA.CL", "DEBTORS.SALES",
"EBIT.FinExp", "logTA", "EBITDA.SALES", "DEBTORS.SALES", "EBITDA.SALES",
"CF.CL", "CA.CL", "CF.NCL", "CA.CL", "CA.CL", "SALES.EBIT", "CA.CL",
"DEBTORS.SALES", "TL.TA", "CF.SALES", "CA.CL", "SALES.FA", "EBIT.FinExp",
"SALES.EBIT", "CF.SALES", "CA.CL", "CF.NCL", "EBIT.Capital",
"DEBTORS.SALES", "EQ.Turnover", "TL.EQ", "EBITDA.SALES", "WC.EBIT",
"SALES.FA", "DEBTORS.SALES"), Ratio = c(-0.707919201865374, 0.534298237128927,
0.763308535784903, -1.24540281291686, 0.332626927584044, -0.485527331169614,
-0.626125641168283, 1.75345016963661, 4.51002074747425, NA, NA,
NA, NA, NA, 0.812093120581957, 0.261889212102065, 0.330583042088873,
1.86055950229721, -0.559740348093955, -0.751550592131927, -0.583664251852244,
-0.522445867895311, -0.686761191590487, -0.582852934868012, -0.388631437021738,
-0.376042040118803, 1.42792549342901, -0.498990070660728, 0.208683983665681,
2.14576274581865, -0.768210439875085, 0.53597295004055, -0.653782593991037,
-0.401467349422482, 0.955113642471936, 1.53488585290567, -0.3952130632778,
NA, 0.144744549336861, -1.11766418734528, NA, -0.486293007398917,
-0.337866870638434, -0.665794733109122, 0.526585766173069, -0.330968739102218,
-1.71872921769721, NA, -0.603494884009451, -0.669873024581416,
NA, -0.649826514192686, 3.07036655149694, NA, 2.13760005383415,
0.48611918602065, -0.46490903620693, 1.76231954464496, -0.904090534873578,
-0.597689611958551, 0.570443208862788, -0.295696356825069, NA,
NA, -1.12026151337091, 0.353252456885539, -0.410737653008626,
-0.492832999764316, -0.964106737223811, 0.771902521119517, -0.690879784763869,
NA, 0.20812644470003, NA, -0.702318717339072, -0.725246730786497,
-0.611066135478997, -0.752358284437105, NA, -0.336177411573904,
NA, -0.972007939780494, NA, 0.588136079183467, -0.189762086807928,
NA, -0.090507528727365, NA, -0.0414476119071152, -0.591736889328259,
-0.5129649441072, 3.38321349285669, -0.83540453095325, NA, -0.464060181907834,
0.170933923104933, -0.48321974573862, -0.724726093759333, 2.13475323186374,
-0.551720107396813, -0.626677016637103, NA, NA, NA, 0.652318574413187,
-1.02928500954333, -0.554231821404908, NA, 0.367065924508534,
4.01819284884926, 0.845766884268474, -0.70159006627801, -0.280390290506344,
-0.626223193308945, -0.4690747657034, NA, NA, -0.890480886392398,
-0.478386122102566, -0.0161475286907884, 0.253289117743233, -0.547105578584289,
0.380874662395742, -0.818329487977687, NA, NA, 0.955752645159877,
NA, NA, -0.994832250856227, -0.449101510108994, 0.0694474558888659,
-0.598563168472843, -0.486097896726921, NA, -0.371989877402075,
NA, -0.318581703636123, NA, -0.100445919052522, 0.799824845462438,
0.378210972442923, 1.27868945760894, 0.24318089910497, 0.181578779346068,
NA, -0.685683467561987, -0.459631884960373, 1.63095980160168,
NA, 0.0946018130113362, 1.02705324936134, 0.671527084464841,
NA, -0.7233085189248, -0.12675734621849, -1.38656705544647, -0.560915914512089,
-0.651921766209563, -0.27953897460903, 0.291991314562734, -0.528392572004289,
NA, NA, 1.50012078788565, NA, NA, NA, 1.31640767511872, -0.445442274834121,
-0.414856728587356, -0.314051160102572, 0.375744307410188, NA,
1.81781116610221, -0.559946887602694, -0.395457514182639, NA,
-0.00526745113271141, -0.332325214798845, -0.018280127030989,
1.62199240527132, -0.594479361680451, -0.564198930580082, NA,
-0.62167492692037, -0.416303523892455, -0.449607506297853, 0.903845712282351,
0.779684646559823, 0.143738281941008, -0.499873895126271, -0.641177881704429,
NA, NA, -0.273314809518737, -0.529847731746218, NA, -0.173764991270002,
-0.354344496593425, NA, 0.478253576057706, NA, -0.187311787706413,
0.123066579596889, -0.513750460779892, NA, -0.790302221045379,
0.804382183064051, NA, -0.297655481061757, -0.629830122961466,
NA, -0.519316349381646, NA, -0.704915022051129, -0.577424583637617,
NA, -0.482010018569492, 0.238837508589818, -0.532068808898047,
0.297453160922741, -0.755306596376328, 0.578212039243233, -0.450857004957819,
-0.748403848598439, -0.37679058952789, 0.0241775484739816, 0.192730082758945,
-0.515145439910768, -0.2268625780629, 3.01576448103222, -0.583866152304867,
-0.709552047052377, 0.425623875604783, -0.176544051505707, -0.620792120166673,
-0.955353796034912, NA, -0.809318960526967, 0.420023768667055,
-0.10523384165629, 0.406993073561131, -0.651798854673955, 0.716344972440134,
-0.303352449044368, -0.668984877006987, NA, -0.564780013255765,
-1.05118700631593, -0.539116726883504, -0.450800652766572, -0.749871688838548,
-0.0841302606072373, -0.709221367461288, -0.490910197160739,
1.11027172778273, NA, -0.601870914727605, -0.552107614649751,
1.62516615465747, 2.44418728489504, -0.409209593330642, NA, -0.960828529382557,
0.084165536089424, -0.705514388724782, -0.610463822925471, 0.497068681435134,
-0.901651796426343, -0.435677866991515, 0.233314727709829, NA,
0.00852960753143773, NA, -0.115106662664484, -0.770897489615408,
-0.0354281980844262, -0.407056468073408, NA, -0.485108803557962,
1.08794794256967, -0.190125931876589, -0.402265379206689, 1.1424132722547,
0.135126477946112, -0.603939243675491, -0.717615437622428, -1.00910526031101,
2.22705685835911, NA, NA, NA, 2.64407175315141, -0.0446459000716095,
0.415476261684389, 0.796821253852406, 0.201011466923258, -0.544530194375183,
-1.22140141358447, -0.360101158862896, 3.45535955026293, NA,
-0.448286766138525, 0.811084846975265, -0.527021372402286, 1.3424732936182,
3.61314912518142, -0.463269606554065, 0.0405953936802976, -0.146586169376855,
NA, 2.12231677541413, NA, -0.636743440094211, -0.615559966343366,
-0.571577080857255, 2.50953454213711, -0.300544588599613, -0.0362964175170153,
-0.619520327701307, -0.502959017927762, -0.372855255378387, 1.31539147808008,
-0.394080181754502, NA, -0.00352084504014205, -0.55495656291638,
0.480334834629862, 1.63500140088775, -1.15012988133644, -0.569867634951047,
0.360801001739192, -0.679469512958559, NA, 0.580475615397198,
NA, 2.25455662583243, -0.759165766527588, -0.451095627447786,
-0.15783276233868, -0.172816536529721, -0.217054425468797, -0.184291097560009,
NA, 0.546420739451911, NA, -0.490529780725351, -0.333472258672436,
-0.438198173702863, -0.646280348380046, -0.630225889980435, -0.705124582982999,
-1.77969797337541, -0.402601268399203, -0.222140988823231, 0.576239927127392,
NA, -0.321675775893816, -0.251829942792891, 1.02695194871569,
0.61619363855965, -0.423739089065777, 0.764954823524791, -0.576377283963124,
0.0839707252843906, -0.466579922080166, -0.484544994892477, -0.397657628622839,
-1.05472151674597, 3.2212462997121, -0.0231910345270541, -0.167537885665263,
-0.492795538660388, 1.97581659699565, -0.499098597312652, 0.56861641397915,
-0.676879586334823, -0.125334637509097, 1.29393839101515, -0.636084619567668,
0.282217561163258, -0.406032294129199, 1.11832771373931, -0.357200115739465,
3.47191854245104, NA, NA, -0.323001011945709, 0.829062755141093,
NA, -0.471688857638298, -0.944225375006027, -0.341659690874536,
-0.420054310804183, -0.455765315492974, NA, NA, -0.362113287165822,
0.77088554356236, 0.315220067697118, -0.0794308626912546, 1.46915410747046,
-0.522548665811739, 0.230255494859231, -0.560629395458324, 0.470723132557846,
-0.761260095149801, -0.476098269898868, NA, -0.669458501886402,
-0.532247910499081, 1.06219015600794, NA, -0.714135539638932,
-0.658027312807696, -0.433435994975457, -0.511392591593316, -0.230059145876329,
NA, 0.0111443539074219, -0.684454010718469, -0.625946669480515,
NA, -0.46617948856222, -0.744977753108209, -0.445294244818825,
-0.702413841896356, -0.714672830111507, NA, NA, NA, 0.85804073380322,
NA, -1.25848825367149, NA, NA, 0.446328793506625, -0.752068298980925,
0.122145113318285, 0.849904783555482, NA, -0.78129893263372,
-0.537436099444471, 0.198639023895424, -0.990836594347679, -0.654663516018546,
1.08110583478396, 1.0640799538555, 0.537681922023906, -0.309706876113679,
-0.439635273472738, NA, -0.368011612232917, NA, 3.50174925043846,
-0.39927048724593, -0.926281959133432, -0.376881673897987, -0.162880850919552,
-0.142649303086233, 1.09678336275476, NA, -0.879837401893792,
-0.414955051475592, -0.920399731144902, -0.699788115735192, 2.57172151516347,
0.267771491217914, 0.171724262110164, NA, 3.06797562926558, -0.241808057899617,
-0.685811369433853, NA, 1.85597513761496, NA, -0.521621841883141,
-0.305316470900169, NA, -0.539698980199801, -0.0720400072423283,
NA, 0.437389975954819, 4.10831662855063, 4.42138430051713, NA,
-0.494316690230473, -0.792706118884541, 2.73285642246282, -0.192689903505749,
-0.492415961149561, NA, -0.974988170595545, -0.21084424861102,
-0.751334790010609, -0.00141664743077581, -0.674592842718741,
0.138632188019161, NA)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -500L))
EDIT: ggplot theme:
library(tidyquant) # for theme_tq()
theme(strip.text=element_blank(),
#aspect.ratio = 1,
axis.line.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position = "bottom",
legend.title = element_text(size = 20),
legend.text = element_text(size = 10),
axis.title = element_text(size = 20),
axis.text = element_text(size = "15"),
strip.text.x = element_text(size = 15),
plot.title = element_text(size = 30),
strip.background = element_rect(fill = 'darkred'),
panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_text(angle = 90),
axis.title.x=element_blank()) +
labs(title=.x[["Model_Name"]][1]) +
theme_tq(base_family = "serif")

We can create a new grouping variable that places the Feature values into one of two groups and then use that grouping variable for faceting.
We then split the data by Model_Name into a list with four elements, one data frame for each level of Model_Name.
Using map, we feed this list of four data frames into ggplot to create a separate plot for each level of Model_Name. The code uses element_textbox_simple from the new ggtext package to add a colored background strip to the title of each plot in order to simulate facet labels (we removed the "real" facet labels because they are non-informative and also because we want the label to appear only once per pair of plots).
We then lay out the four plots using the patchwork package.
library(tidyverse)
library(patchwork)
# remotes::install_github("wilkelab/ggtext")
library(ggtext)
# Set general plot theme
theme_set(theme_classic() +
theme(panel.background=element_rect(colour="grey40", fill=NA)))
pd = position_dodge(width=0.9)
# Create a list of four ggplots, one for each level of Model_Name
pl = d %>%
# Create grouping variable to split Feature into two groups
mutate(group = ifelse(as.numeric(factor(Feature)) <= 0.5*length(unique(Feature)),
"g1","g2")) %>%
# Split data into a list of four data frames, one for each level of Model_Name
group_split(Model_Name) %>%
# Create a list of four plots
map(
~ ggplot(.x, aes(x = Feature, y = Ratio, fill = Status)) +
geom_violin(alpha = 0.5, scale = "width", position = pd) +
geom_boxplot(alpha = 1, width = 0.2, position = pd) +
scale_y_continuous(limits = c(-3, 4)) +
facet_wrap(~ group, ncol=1, scales="free_x") +
theme(strip.background=element_blank(),
strip.text=element_blank(),
axis.title.x=element_blank(),
plot.title=element_textbox_simple(fill="grey80",
halign=0.5, size=11,
padding=margin(t=4, b=2))) +
labs(title=.x[["Model_Name"]][1])
)
# Add single x-axis title to bottom plot
pl[[4]] = pl[[4]] +
theme(axis.title.x=element_text(margin=margin(t=5))) +
labs(x="Feature")
wrap_plots(pl, ncol=1) + plot_layout(guides="collect")

Related

xAxis order of R highcharter column plot

With the following data frame:
dta <- structure(list(sociodemographic_var = structure(c(3L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 26L, 18L, 20L, 21L, 26L, 13L, 16L, 21L, 22L, 26L, 26L,
9L, 13L, 17L, 18L, 20L, 21L, 23L, 26L, 20L, 26L), levels = c("1st grade",
"2nd grade", "3rd grade", "4th grade", "5th grade", "6th grade",
"7th grade", "8th grade", "9th grade", "10th grade", "11th grade",
"12th grade, no diploma", "High school graduate", "GED or equivalent",
"Some college, no degree", "Less than 1 year of college credit/post-secondary education (or less than 10 classes)",
"One year or more of college credit, no degree", "Associate degree: Occupational, Technical, or Vocational",
"Associate degree: Academic Program", "Bachelor's degree (ex. BA, AB, BS, BBS)",
"Master's degree (ex. MA, MS, MEng, MEd, MBA)", "Professional School degree (ex. MD, DDS, DVN, JD)",
"Doctoral degree (ex. PhD, EdD)", "Refused to answer", "Don't Know",
"unknown"), class = "factor"), event = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 7L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 11L, 11L), levels = c("Baseline", "0.5 Year", "1 Year",
"1.5 Year", "2 Year", "2.5 Year", "3 Year", "3.5 Year", "4 Year",
"4.5 Year", "5 Year", "5.5 Year", "6 Year", "Screener"), class = "factor"),
visit_type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), levels = c("on-site", "hybrid", "remote", "unknown"), class = "factor"),
n = c(2L, 13L, 5L, 9L, 15L, 18L, 26L, 25L, 192L, 27L, 485L,
224L, 183L, 1011L, 666L, 55L, 78L, 3L, 9L, 1L, 1L, 2L, 208L,
1L, 1L, 1L, 1L, 126L, 28L, 1L, 1L, 2L, 2L, 3L, 4L, 1L, 543L,
1L, 300L)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-39L))
I would assume that, generating a highcharter bar plot with:
library(highcharter) # v0.9.4
dta |>
hchart(type = "column", hcaes(x = "event", y = "n", group = "sociodemographic_var")) |>
hc_yAxis(title = list(text = "%"), max = 115, endOnTick = FALSE, stackLabels = list(enabled = TRUE)) |>
hc_xAxis(title = "") |>
hc_plotOptions(series = list(stacking = "percent"))
the xAxis would be ordered by levels(dta$event):
levels(dta$event)
[1] "Baseline" "0.5 Year" "1 Year" "1.5 Year" "2 Year" "2.5 Year" "3 Year" "3.5 Year" "4 Year" "4.5 Year" "5 Year" "5.5 Year"
[13] "6 Year" "Screener"
But the ordering is different and neither alphabetical nor based on the total number of values:
I am interested to understand why it's the case and how to set the order right.
You can add categories to your hc_xAxis to make an order like this:
library(highcharter)
dta |>
hchart(type = "column", hcaes(x = "event", y = "n", group = "sociodemographic_var")) |>
hc_yAxis(title = list(text = "%"), max = 115, endOnTick = FALSE, stackLabels = list(enabled = TRUE)) |>
hc_xAxis(title = "", categories = levels(dta$event)) |>
hc_plotOptions(series = list(stacking = "percent"))
Output:

R programming - How to work with column conditions while dataframe base contains characters

I have a mixed database in excel which has a numeric and characters columns.
The final outcome should be various plots that describe our research question which is if there is any connection between district, job sector and more to uneployments percentage.
I did a lot of searching and nothing comes up as far as it comes to characters columns.
So, I need your help in understanding how can I make a conditional command to create a subset of this database which summarise it.
Here's how the database looks like:
Cdata <-
structure(
list(
Month = c(
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01",
"2020-01"
),
District = c(
"Center",
"Center",
"Center",
"Center",
"Center",
"Center",
"Center",
"Center",
"Center",
"Center"
),
Age = c(
"Under 17",
"Under 17",
"Under 17",
"18-24",
"18-24",
"18-24",
"18-24",
"18-24",
"18-24",
"18-24"
),
Gender = c(
"Male",
"Male",
"Female",
"Male",
"Male",
"Male",
"Male",
"Male",
"Male",
"Male"
),
Education = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"),
MedicalDisability = c(
"Without any",
"Without any",
"Without any",
"Without any",
"Without any",
"Without any",
"Without any",
"Without any",
"Without any",
"Without any"
),
Religion = c(
"Jewish",
"Muslims",
"Other",
"Jewish",
"Jewish",
"Jewish",
"Jewish",
"Jewish",
"Jewish",
"Jewish"
),
UneploymentDays = c(
"0-30",
"Over 270",
"Over 270",
"0-30",
"0-30",
"0-30",
"0-30",
"0-30",
"0-30",
"31-180"
),
Occupation = c(
"Laboring class",
"Sales \\ Costumer service",
"Undefinded",
"Laboring class",
"Academic degree",
"Practical engineers / Technicians",
"Undefinded",
"Sales \\ Costumer service",
"Laboring class",
"Practical engineers / Technicians"
),
Jobseekers = c(2L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 2L),
GMI = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L),
ACU = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L),
NACU = c(2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 5L, 2L),
NewSeekers = c(0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L,
0L, 0L),
NewFiredSeekers = c(0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L)
),
row.names = c(NA, 10L),
class = "data.frame"
)
i need a new dataset that looks like this:
District Jobseekers GMI ACU NACU
North 1024 8710 3245 3256
Center 57691 12160 8710 14320
South 21516 9821 5289 18172
And than sort it all over again by age:
Age Jobseekers GMI ACU NACU
Under 17 1024 8710 3245 3256
18-24 57691 12160 8710 14320
25-34 21516 9821 5289 18172
45-54 4682 7142 2365 6128
55-64 1999 1991 2839 1927
Over 64 10918 4289 1378 5368
And than, finally, i need to make plots for each category that shows statistics and make statistic tests as i described.
Hope i made my point clearly now.
as for the codes, i've tried so many structures and examples, non of them really helped.
Let me make it clear - I don't want you to do my work or write the whole code for me, but at the same time i'll mentioned i'm a newbie in R language, and i do this task as a part of a project in data science course.
If anything else needed, please let me know.
Here's a screenshot of the database: https://imgur.com/a/7fDGuuK
Thanks,
Moshe

rearranging ggplot axis groups in plot

I am trying to rearrange my plot such that it follows the correct confusion matrix structure from the caret package.
For example, I have the following confusion matrix table:
Prediction 0 1
0 3444 265
1 98 148
Where the 1 is the bankrupt case and the 0 is the Non-Bankrupt case in my data. I seem to have my data the opposite of what I want it to look like.
Other confusion matrix:
Reference
Prediction 0 1
0 3317 313
1 87 164
Reference
Prediction 0 1
0 3079 308
1 78 182
Reference
Prediction 0 1
0 2980 335
1 106 144
I want to rearrange the plots such at (for the first confusion matrix) the 3444 number and points are in the upper quadrant with the text "Non-Bankrupt" next to it (which is the 0 in the confusion matrix). The 148 should be in the bottom right quadrant. The 265 should be in the upper right quadrant and the 98 should be in the bottom left quadrant. (Just as displayed in the first confusion matrix)
Code:
d %>%
ggplot(aes(x = pred_status, y = status, color = correct)) +
geom_jitter() +
geom_text(aes(label = n), size = 15, color = "black", family = "serif") +
facet_wrap(~Model_Name) +
scale_x_discrete(labels = c("Non-Bankrupt", "Bankrupt")) +
scale_y_discrete(labels = c("Non-Bankrupt", "Bankrupt"))
Sample of the data:
d <- structure(list(pred_status = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,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 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Correct",
"Incorrect"), class = "factor"), n = c(2980L, 2980L, 313L,
3444L, 2980L, 3444L, 3444L, 2980L, 3317L, 2980L, 3317L, 3317L,
182L, 3317L, 3079L, 2980L, 3444L, 3444L, 3317L, 3079L, 3079L,
144L, 3444L, 3444L, 3079L, 2980L, 2980L, 3444L, 3444L, 3317L,
3444L, 3444L, 2980L, 3444L, 3317L, 3079L, 3079L, 3079L, 3444L,
2980L, 3317L, 3444L, 3444L, 3317L, 144L, 3079L, 2980L, 2980L,
3317L, 3079L, 182L, 335L, 3444L, 3317L, 3444L, 3444L, 3444L,
106L, 3079L, 3317L, 3079L, 3079L, 3444L, 3444L, 3079L, 164L,
3444L, 2980L, 3079L, 2980L, 3079L, 164L, 3317L, 3317L, 2980L,
148L, 313L, 3444L, 3079L, 3317L, 3444L, 3079L, 3444L, 3317L,
3444L, 3444L, 3079L, 3444L, 3317L, 3079L, 144L, 3079L, 3317L,
3317L, 3079L, 3317L, 3444L, 2980L, 3317L, 2980L, 3444L, 2980L,
3079L, 3079L, 3444L, 3444L, 2980L, 3317L, 3317L, 2980L, 3079L,
98L, 3079L, 3444L, 3444L, 2980L, 3317L, 3079L, 3444L, 2980L,
3079L, 3317L, 144L, 182L, 3317L, 3079L, 2980L, 3079L, 3444L,
313L, 2980L, 3317L, 3444L, 3317L, 3317L, 3079L, 2980L, 3444L,
182L, 3079L, 3317L, 3444L, 265L, 164L, 335L, 3079L, 2980L,
2980L, 3444L, 3079L, 3444L, 2980L, 3317L, 148L, 3444L, 2980L,
3079L, 3444L, 3079L, 2980L, 3317L, 3444L, 2980L, 98L, 3317L,
78L, 3317L, 2980L, 3079L, 106L, 3079L, 3079L, 3079L, 2980L,
2980L, 3317L, 2980L, 3444L, 3444L, 3079L, 2980L, 3444L, 3079L,
2980L, 3317L, 3317L, 164L, 308L, 3317L, 3444L, 313L, 3444L,
3317L, 3444L, 2980L, 3317L, 3317L, 3444L, 2980L, 3444L),
Model_Name = c("4 Year", "4 Year", "2 Year", "1 Year", "4 Year",
"1 Year", "1 Year", "4 Year", "2 Year", "4 Year", "2 Year",
"2 Year", "3 Year", "2 Year", "3 Year", "4 Year", "1 Year",
"1 Year", "2 Year", "3 Year", "3 Year", "4 Year", "1 Year",
"1 Year", "3 Year", "4 Year", "4 Year", "1 Year", "1 Year",
"2 Year", "1 Year", "1 Year", "4 Year", "1 Year", "2 Year",
"3 Year", "3 Year", "3 Year", "1 Year", "4 Year", "2 Year",
"1 Year", "1 Year", "2 Year", "4 Year", "3 Year", "4 Year",
"4 Year", "2 Year", "3 Year", "3 Year", "4 Year", "1 Year",
"2 Year", "1 Year", "1 Year", "1 Year", "4 Year", "3 Year",
"2 Year", "3 Year", "3 Year", "1 Year", "1 Year", "3 Year",
"2 Year", "1 Year", "4 Year", "3 Year", "4 Year", "3 Year",
"2 Year", "2 Year", "2 Year", "4 Year", "1 Year", "2 Year",
"1 Year", "3 Year", "2 Year", "1 Year", "3 Year", "1 Year",
"2 Year", "1 Year", "1 Year", "3 Year", "1 Year", "2 Year",
"3 Year", "4 Year", "3 Year", "2 Year", "2 Year", "3 Year",
"2 Year", "1 Year", "4 Year", "2 Year", "4 Year", "1 Year",
"4 Year", "3 Year", "3 Year", "1 Year", "1 Year", "4 Year",
"2 Year", "2 Year", "4 Year", "3 Year", "1 Year", "3 Year",
"1 Year", "1 Year", "4 Year", "2 Year", "3 Year", "1 Year",
"4 Year", "3 Year", "2 Year", "4 Year", "3 Year", "2 Year",
"3 Year", "4 Year", "3 Year", "1 Year", "2 Year", "4 Year",
"2 Year", "1 Year", "2 Year", "2 Year", "3 Year", "4 Year",
"1 Year", "3 Year", "3 Year", "2 Year", "1 Year", "1 Year",
"2 Year", "4 Year", "3 Year", "4 Year", "4 Year", "1 Year",
"3 Year", "1 Year", "4 Year", "2 Year", "1 Year", "1 Year",
"4 Year", "3 Year", "1 Year", "3 Year", "4 Year", "2 Year",
"1 Year", "4 Year", "1 Year", "2 Year", "3 Year", "2 Year",
"4 Year", "3 Year", "4 Year", "3 Year", "3 Year", "3 Year",
"4 Year", "4 Year", "2 Year", "4 Year", "1 Year", "1 Year",
"3 Year", "4 Year", "1 Year", "3 Year", "4 Year", "2 Year",
"2 Year", "2 Year", "3 Year", "2 Year", "1 Year", "2 Year",
"1 Year", "2 Year", "1 Year", "4 Year", "2 Year", "2 Year",
"1 Year", "4 Year", "1 Year")), row.names = c(NA, -200L), class = c("tbl_df",
"tbl", "data.frame"))
I tried and came up with this minor changes:
library(tidyverse)
d %>%
ggplot(aes(x = status, y = fct_rev(pred_status), color = correct)) +
geom_jitter() +
geom_text(aes(label = n), size = 15, color = "black", family = "serif") +
facet_wrap(~Model_Name) +
scale_x_discrete(labels = c("Non-Bankrupt", "Bankrupt")) +
scale_y_discrete(labels = c("Bankrupt", "Non-Bankrupt"))
Which gives me this figure:
Not 100% sure if the labels are correct now?รจ

Using a regression model to predict values

I am currently working with 2 separate CSV datasets. I have already used the first data set named PRICEtable4.1 to visualize a relationship between the x values (GBA) and the y values (PRICE). I have attached a picture of the graph right below.
What I need to do now is use that cubic regression model from the first CSV dataset to predict the y values (PREDICTED_PRICE) in the second CSV dataset based on the x values (GBA) given. Is there a function that lets me make that connection? The code I used to create the regression model is below
train_X <- PRICEtable4.1$GBA
train_y <- PRICEtable4.1$PRICE
test_X <- PRICEtable4.1$GBA
test_y <- PRICEtable4.1$PRICE
X <- train_X
view(X)
y <- train_y
View(y)
poly_order <- 3
model <- lm (y~poly(X, poly_order))
print(model)
#MSE
test_yhat <- predict(model, data.frame (X = test_X))
MSE <- mean((test_y-test_yhat )^2)
print(MSE)
#R squared
test_ymean <- mean(test_y)
test_yhatmean <- mean( test_yhat)
R_squared <- (sum((test_yhat-test_yhatmean)*(test_y-test_ymean)))^2/(sum((test_yhat-test_yhatmean)^2)*sum((test_y-test_ymean)^2))
print(R_squared)
error2 <- data.frame(MSE=c(MSE),R_squared=c(R_squared))
View(error2)
#Visualization of the model
X_new = X
View(X_new)
y_new <- predict(model, data.frame (X = X_new))
View(y_new)
PRICEmodel <- ggplot(PRICEtable4.1,aes(x=GBA,y=PRICE))+geom_point(size=2)
PRICEmodel+geom_line(aes(x=X_new,y=y_new),color="Red") + labs(x="Gross building area (ft^2)", y="Price", title="Price Regression Model")
Here's a dput of the first dataset named PRICEtable4.1 (first 20 rows)
structure(list(ID = c(1L, 2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L), GBA = c(1324L,
2120L, 1216L, 1804L, 1836L, 1228L, 1312L, 1262L, 1461L, 1120L,
1037L, 832L, 1500L, 920L, 1565L, 1134L, 1184L, 1420L, 2082L,
1422L), PRICE = c(1375000L, 1467000L, 549410L, 1180000L, 828000L,
742000L, 829000L, 710000L, 775000L, 380000L, 600000L, 189000L,
200000L, 265000L, 560000L, 300000L, 200000L, 940000L, 1050000L,
979000L)), row.names = c(NA, 20L), class = "data.frame")
Here's the dput of the second CSV dataset named Test (first 20 rows)
structure(list(ID = c(1L, 2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L), GBA = c(1324L,
2120L, 1216L, 1804L, 1836L, 1228L, 1312L, 1262L, 1461L, 1120L,
1037L, 832L, 1500L, 920L, 1565L, 1134L, 1184L, 1420L, 2082L,
1422L), PRICE = c(1375000L, 1467000L, 549410L, 1180000L, 828000L,
742000L, 829000L, 710000L, 775000L, 380000L, 600000L, 189000L,
200000L, 265000L, 560000L, 300000L, 200000L, 940000L, 1050000L,
979000L)), row.names = c(NA, 20L), class = "data.frame")
> dput(Test[1:20, ])
structure(list(ID = 1:20, BATHRM = c(2L, 2L, 1L, 3L, 4L, 2L,
1L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 2L, 3L, 2L), HF_BATHRM = c(1L,
1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L,
0L, 1L, 0L), HEAT = c("Forced Air", "Forced Air", "Warm Cool",
"Forced Air", "Forced Air", "Warm Cool", "Hot Water Rad", "Forced Air",
"Warm Cool", "Forced Air", "Forced Air", "Hot Water Rad", "Forced Air",
"Forced Air", "Warm Cool", "Forced Air", "Forced Air", "Warm Cool",
"Ht Pump", "Forced Air"), AC = c("Y", "Y", "N", "Y", "Y", "Y",
"N", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "Y", "Y", "Y",
"Y"), NUM_UNITS = c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L), ROOMS = c(9L, 7L, 6L, 7L,
13L, 5L, 7L, 7L, 6L, 7L, 7L, 8L, 5L, 8L, 5L, 8L, 6L, 8L, 10L,
7L), BEDRM = c(3L, 3L, 3L, 4L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
2L, 4L, 2L, 4L, 3L, 2L, 3L, 3L), AYB = c(1870L, 1890L, 1911L,
1920L, 1993L, 1947L, 1895L, 1910L, 1910L, 1950L, 1951L, 1928L,
1941L, 2018L, 1939L, 2018L, 1980L, 1951L, 1910L, 1908L), YR_RMDL = c(1980L,
1963L, NA, 2001L, 2018L, NA, 1987L, 2017L, NA, NA, NA, NA, NA,
NA, 1992L, NA, 2013L, 2005L, 2004L, 1984L), EYB = c(1967L, 1982L,
1957L, 1972L, 2003L, 1958L, 1957L, 1964L, 1954L, 1960L, 1951L,
1954L, 1961L, 2018L, 1957L, 2018L, 1991L, 1961L, 1975L, 1960L
), STORIES = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1.75, 2, 1, 2,
2, 2, 2, 2, 2), GBA = c(1324L, 2120L, 1216L, 1804L, 5036L, 1836L,
1228L, 1312L, 1262L, 1461L, 1120L, 1037L, 832L, 1500L, 920L,
1565L, 1134L, 1184L, 1420L, 2082L), BLDG_NUM = c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), STYLE = c("2 Story", "2 Story", "2 Story", "2 Story", "2 Story",
"2 Story", "2 Story", "2 Story", "2 Story", "2 Story", "2 Story",
"2 Story", "2 Story", "1 Story", "2 Story", "2 Story", "2 Story",
"2 Story", "2 Story", "2 Story"), STRUCT = c("Row Inside", "Row Inside",
"Row Inside", "Single", "Single", "Single", "Row Inside", "Row Inside",
"Row Inside", "Single", "Semi-Detached", "Single", "Row Inside",
"Semi-Detached", "Semi-Detached", "Single", "Row Inside", "Multi",
"Row Inside", "Row Inside"), LANDAREA = c(1575L, 1800L, 1280L,
5000L, 10252L, 3000L, 1500L, 1641L, 1358L, 6300L, 1818L, 3500L,
1280L, 5098L, 1899L, 5009L, 1152L, 2910L, 1762L, 1400L), ASSESSMENT_NBHD = c("Old City 2",
"Capitol Hill", "Old City 1", "Palisades", "Chevy Chase", "Chevy Chase",
"Eckington", "Ledroit Park", "Eckington", "Riggs Park", "Riggs Park",
"Woodridge", "Lily Ponds", "Fort Dupont Park", "Hillcrest", "Hillcrest",
"Congress Heights", "Congress Heights", "Old City 1", "Capitol Hill"
), PREDICTED_PRICE = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, 20L
), class = "data.frame")
So I need to predict and fill out the values in the "PREDICTED_PRICE" column in the second CSV dataset using the regression model I created from the first dataset

Greek letters in nested facets in ggplot2

I have a huge dataset and I need to plot in facets with one nested facets in x axis(alpha and de id of replicate) and in y axis (beta)
fen_ale_all_rep$alpha <- factor(
fen_ale_all_rep$alpha,
levels = c("alpha 0.1", "alpha 0.2", "alpha 0.4", "alpha 0.8", "alpha 1.6"),
labels = c(
"alpha '0.1'",
"alpha '0.2'",
"alpha '0.4'",
"alpha '0.8'",
"alpha '1.6'"
)
)
fen_ale_rep5$beta <- factor(
fen_ale_rep5$beta,
levels = c(
"beta 0.05",
"beta 0.1",
"beta 0.2",
"beta 0.4",
"beta 0.8",
"beta 1.6",
"beta 3.2",
"beta 6.4",
"beta 12.8",
"beta 25.6",
"beta 51.2",
"beta 102.4"
),
labels = c(
"beta 0.05",
"beta 0.1",
"beta 0.2",
"beta 0.4",
"beta 0.8",
"beta 1.6",
"beta 3.2",
"beta 6.4",
"beta 12.8",
"beta 25.6",
"beta 51.2",
"beta 102.4"
)
)
structure:
tbl <- structure(list(FEN = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = c("Plants", "Insects"), class = "factor"),
NSEL = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1), rep = c("rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1",
"rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1"
), alpha = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L), .Label = c("alpha 0.1", "alpha 0.2",
"alpha 0.4", "alpha 0.8", "alpha 1.6"), class = "factor"),
beta = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L), .Label = c("beta 0.05", "beta 0.1",
"beta 0.2", "beta 0.4", "beta 0.8", "beta 1.6", "beta 3.2",
"beta 6.4", "beta 12.8", "beta 25.6", "beta 51.2", "beta 102.4"
), class = "factor"), TEMPO = c(1L, 200L, 400L, 600L, 800L,
1000L, 1200L, 1400L, 1600L, 1800L, 2000L, 2200L, 2400L, 2600L,
2800L, 3000L, 3200L, 3400L, 3600L, 3800L, 4000L, 4200L, 4400L,
4600L, 4800L, 5000L, 5200L, 5400L, 5600L, 5800L, 6000L, 6200L,
6400L, 6600L, 6800L, 7000L, 7200L, 7400L, 7600L, 7800L, 8000L,
8200L, 8400L, 8600L, 8800L, 9000L, 9200L, 9400L, 9600L, 9800L,
10000L, 1L, 200L, 400L, 600L, 800L, 1000L, 1200L, 1400L,
1600L), ab = c("0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05",
"0.1 0.05", "0.1 0.05", "0.1 0.1", "0.1 0.1", "0.1 0.1",
"0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1"
), especie = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1"), trait = c(0.59532188, 0.63023233, 0.59210289,
0.58660778, 0.55932657, 0.57032034, 0.56379332, 0.61973847,
0.61705717, 0.62310601, 0.61690676, 0.6508817, 0.64581712,
0.5890861, 0.66424559, 0.64007846, 0.52734623, 0.65276626,
0.57025516, 0.59734711, 0.59672837, 0.57971204, 0.51274562,
0.60679023, 0.56463537, 0.64716034, 0.60257023, 0.68582648,
0.62075915, 0.46707366, 0.65330306, 0.59301249, 0.70620201,
0.5260134, 0.51619464, 0.65620395, 0.48348558, 0.62189428,
0.60360017, 0.55274833, 0.56492948, 0.61039593, 0.75225962,
0.54349533, 0.47189362, 0.52454647, 0.56282583, 0.63985652,
0.58380379, 0.59214658, 0.73188778, 0.62808414, 0.59229323,
0.6978987, 0.61346245, 0.49995094, 0.4661158, 0.57436886,
0.58524132, 0.60717574)), row.names = c(NA, 60L), class = "data.frame")
I can produce this plot:
But, it doesn't show the replicate id. and the betas doesn't follow the crescent order.
I would like something like:
or one single facet with replicate and de columns with each alpha value (0.1,0.2,....)
for(i in 1:10) {
grid1 <- print(
ggplot(
fen_ale_all_rep,
aes(
x = TEMPO,
y = trait,
group = interaction(FEN, ab, especie, rep),
colour = FEN
)
) +
geom_line() +
labs(x = "Time",
y = "Mean phenotypes") +
scale_color_viridis(discrete=TRUE,
name = NULL
) +
theme_pubclean() + theme(
axis.text.x = element_text(
size = 15,
angle = 0,
vjust = 0.3
),
axis.text.y = element_text(size = 15),
plot.title = element_text(size = 15),
legend.text = element_text(size = 15),
axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
strip.text.x = element_text(size = 15),
strip.text.y = element_text(size = 15),
plot.caption = element_text(size=15),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.ticks = element_blank(),
legend.position = "top"
) +
facet_grid_paginate(
beta ~ alpha+rep,
ncol = 5,
nrow = 6,
page = i, labeller = label_bquote(beta == .(beta), alpha == .(alpha)))))
}
How can I achieve that?
thanks in advance! and sorry about my english :)

Resources