# Design Layout for Facets ------------------------------------------------ design <- " E C A D B F " # # design <- " # A # " # Facet wrangling --------------------------------------------------------- df <- secaxisdata1 |> mutate( Date = as.Date(Date)) # GGh4X Sec Axis Transformation Formulae - in test replacement for the old Mult ---------------------------------- sec <- help_secondary(df, primary = n, secondary = Performance, method = c("range"), labels = scales::percent, guide = guide_axis_colour(colour = "dodgerblue2"), breaks = c(seq(0,1,.2))) plot <- df |> ggplot() + geom_bar( aes(fill=Category,x=Date, y=BNB), stat="identity", position = "stack", alpha = 0.6 )+ #scale_fill_manual(values = c("Green","Red","Lightblue","Blue"))+ scale_fill_brewer(palette = "Greys",direction = -1) + #BuPu #Paired #Blues #Greys # Mult Line --------------------------------------------------------------- geom_line( aes(x=Date, y = Performance/mult, colour = '% Performance'), stat="identity")+ # GGH4X Line -------------------------------------------------------------- # geom_line(aes(x=Date,y = sec$proj(Performance), colour = '% Performance')) + labs(colour="Performance")+ scale_color_manual(values = c("dodgerblue2","forestgreen"))+ guides(fill = guide_legend(override.aes = list(size= 3))) + new_scale_fill() + # Mult Point -------------------------------------------------------------- geom_point( aes(x=Date,y=Performance/mult), #fill = `Point Index` shape = 21, colour = "dodgerblue2", #0072B2 #navy #7B7D7D fill = "deepskyblue", #grey80 size = 0.8, stroke = 0.3 )+ # GGH4X Point ------------------------------------------------------------- # # geom_point(aes(x=Date,y = sec$proj(Performance)), # shape = 21, # colour = "dodgerblue2", #0072B2 #navy #7B7D7D # fill = "deepskyblue", #grey80 # size = 0.8, # stroke = 0.3) + scale_fill_manual(values = my_values) + coord_cartesian(clip = 'off') + scale_x_date( date_breaks = "1 months", # minor_breaks = " week", # guide = "axis_minor", date_labels = "%b %y", expand = c(0,0), limits = c(min(df$Date)-4,max(df$Date)+7) ) + ylab(NULL)+ # ylab("Discharge Summary Letters sent (Bars)")+ # Mult Sec_axis Scaler (Always the 0-100 scale) ---------------------------------------------------- ggplot2::scale_y_continuous( sec.axis = ggplot2::sec_axis( trans = ~ ((.) / sum(.) * 550), labels = scales::percent, breaks= seq(0,1,.2), name = "Performance % (Line)" ),expand = expansion(mult = c(0, 0.05)) ) + # ggh4x sec.axis scaler (Flexible scale, zooms in on populated part) --------------------------------------------------- # # scale_y_continuous(sec.axis = sec, # expand = expansion(mult = c(0, 0.1)) # # ,guide = guide_axis_colour(colour = "red")) # )+ theme_classic() + theme( axis.text.x = element_text(angle = 40, vjust = 1, hjust=1.0, size = 7.5, colour = "grey25" ), axis.text.y.left = element_text(color = "grey25"), axis.text.y.right = element_text(color = "grey25"), axis.title.x = element_text(color = "grey15") , axis.title.y = element_text(color = "grey15") ) + theme( panel.background = element_rect(fill = "White", colour = NA), axis.line.x = element_line(colour = "grey50",size = 0.5), axis.line.y = element_line(colour = "grey50",size = 0.5), axis.ticks = element_line(colour = "grey50", size = 0.5), axis.ticks.length=unit(.15, "cm") ) + labs( x = '', title = 'With sec_axis multiple Trans method' ) + theme( # plot.title = element_text(vjust = 1), plot.subtitle = element_text(vjust = 2,color = "grey15",size = 9), plot.caption = element_text(color = "grey35", face = "italic"), legend.position = "bottom", legend.background = element_rect(color = "grey60", fill = "White"), legend.key = element_rect(fill = "white", color = NA), legend.key.size = unit(0.3, "cm"), legend.title = element_text(color = "Black", size = 9, face = "bold"), legend.text = element_text(color = "grey10", size = 7.5, face = "plain") ) + theme( strip.background = element_rect( color="grey60", fill= NA, size=0.5, linetype="solid" ), strip.text = element_text(color="grey5" # size=12 ) ) + guides(fill = guide_legend(override.aes = list(size= 2.5,shape = 21))) + facet_manual( vars(fct_relevel(facet,levels = c())), scales = "free_y", remove_labels = "x", design = design) plot