Hello,
Can you please help me figure out how to get different horizontal lines on each facet? I Have successfully created the 3 lines for the 3 facets, but all 3 lines appear on all 3 facets. I would like to have only one of those lines on each respective facet. I feel like I'm doing exactly what the various helpers are saying to do, but can't get it!
Here is my example...this is the first time I've tried using reprex, so I'm not sure I did it right.
Thanks! -Ryan
data_hline <- data.frame(group = unique(PercentCompliant$SubMeasureID),
hline = c(.5729, .3936, .93))
#> Error in unique(PercentCompliant$SubMeasureID): object 'PercentCompliant' not found
Created on 2023-01-05 with reprex v2.0.2
PercentCompliant %>%
ggplot(aes(x = Provider_ShortName,
y = PercentCompliant)) +
geom_point(aes(color = Provider_ShortName,
size = (PercTotalEligible))) +
geom_segment(aes(x = Provider_ShortName,
xend = Provider_ShortName,
y = 0,
yend = PercentCompliant,
color = Provider_ShortName))+
geom_hline(data = data_hline,
aes(yintercept = hline))+
facet_grid(cols = vars(SubMeasureID),
scales = "fixed",
space = "fixed"
#labeller = (SubMeasureID = SubMeasureLabs)
)
#> Error in PercentCompliant %>% ggplot(aes(x = Provider_ShortName, y = PercentCompliant)): could not find function "%>%"
Created on 2023-01-05 with reprex v2.0.2
The data is:
> dput(head(PercentCompliant, 100))
structure(list(Provider_ShortName = c("CPI", "CPI", "CPI", "EHS",
"EHS", "EHS", "LCBHC", "LCBHC", "LCBHC", "MMHC", "MMHC", "MMHC",
"PH", "PH", "PH", "SBHS", "SBHS", "SBHS", "SHG", "SHG", "SHG",
"TGC", "TGC", "TGC", "CBI", "CBI", "CBI"), SubMeasureID = c("AMM2",
"FUH7", "HDO", "AMM2", "FUH7", "HDO", "AMM2", "FUH7", "HDO",
"AMM2", "FUH7", "HDO", "AMM2", "FUH7", "HDO", "AMM2", "FUH7",
"HDO", "AMM2", "FUH7", "HDO", "AMM2", "FUH7", "HDO", "AMM2",
"FUH7", "HDO"), TotalEligible = c(277, 147, 484, 55, 26, 93,
81, 31, 177, 377, 174, 905, 162, 78, 245, 520, 220, 849, 101,
51, 122, 113, 53, 118, 162, 69, 156), PercentCompliant = c(0.664259927797834,
0.496598639455782, 0.935950413223141, 0.654545454545455, 0.461538461538462,
0.946236559139785, 0.592592592592593, 0.354838709677419, 0.932203389830508,
0.676392572944297, 0.511494252873563, 0.974585635359116, 0.666666666666667,
0.5, 0.975510204081633, 0.630769230769231, 0.386363636363636,
0.963486454652532, 0.633663366336634, 0.352941176470588, 0.942622950819672,
0.663716814159292, 0.39622641509434, 0.966101694915254, 0.592592592592593,
0.27536231884058, 0.955128205128205), PercTotalEligible = c(0.149891774891775,
0.173144876325088, 0.15369958717053, 0.0297619047619048, 0.0306242638398115,
0.0295331851381391, 0.0438311688311688, 0.0365135453474676, 0.0562083201016196,
0.204004329004329, 0.204946996466431, 0.28739282311845, 0.0876623376623377,
0.0918727915194346, 0.077802476976818, 0.281385281385281, 0.259128386336867,
0.269609399809463, 0.0546536796536797, 0.0600706713780919, 0.0387424579231502,
0.0611471861471861, 0.0624263839811543, 0.0374722134010797, 0.0876623376623377,
0.0812720848056537, 0.0495395363607494)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -27L), groups = structure(list(
SubMeasureID = c("AMM2", "FUH7", "HDO"), .rows = structure(list(
c(1L, 4L, 7L, 10L, 13L, 16L, 19L, 22L, 25L), c(2L, 5L,
8L, 11L, 14L, 17L, 20L, 23L, 26L), c(3L, 6L, 9L, 12L,
15L, 18L, 21L, 24L, 27L)), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -3L), .drop = TRUE))