@@ -67,16 +67,14 @@ splnr_get_featureRep <- function(soln, pDat, targets = NA,
6767
6868 ns1 <- dplyr :: left_join(area_feature , selected_feature , by = " feature" ) %> %
6969 dplyr :: mutate(
70- relative_held = (.data $ absolute_held / .data $ total_amount ),
71- incidental = TRUE
70+ relative_held = (.data $ absolute_held / .data $ total_amount )
7271 )
7372 } else {
7473 ns1 <- tibble :: tibble(
7574 feature = " DummyVar" ,
7675 total_amount = 0 ,
7776 absolute_held = 0 ,
78- relative_held = 0 ,
79- incidental = TRUE
77+ relative_held = 0
8078 )
8179 }
8280
@@ -121,8 +119,7 @@ splnr_get_featureRep <- function(soln, pDat, targets = NA,
121119
122120 s1 <- s1 %> %
123121 dplyr :: mutate(
124- relative_held = .data $ relative_held ,
125- incidental = FALSE
122+ relative_held = .data $ relative_held
126123 ) %> %
127124 stats :: na.omit()
128125
@@ -134,6 +131,10 @@ splnr_get_featureRep <- function(soln, pDat, targets = NA,
134131 df <- s1
135132 }
136133
134+ # Now add in incidental for 0 and NA targets
135+ df <- df %> %
136+ dplyr :: mutate(incidental = dplyr :: if_else(target > 0 & absolute_held > 0 , FALSE , TRUE , missing = TRUE ))
137+
137138 return (df )
138139}
139140
@@ -257,9 +258,12 @@ splnr_plot_featureRep <- function(df,
257258 ) %> %
258259 tibble :: deframe()
259260
261+
260262 gg_target <- ggplot2 :: ggplot() +
261- ggplot2 :: geom_bar(data = df , stat = " identity" , ggplot2 :: aes(x = .data $ feature , y = .data $ relative_held , fill = .data $ category ), na.rm = TRUE ) +
262- ggplot2 :: geom_bar(data = df %> % dplyr :: filter(.data $ incidental == TRUE ), stat = " identity" , ggplot2 :: aes(x = .data $ feature , y = .data $ relative_held ), na.rm = TRUE , fill = " NA" , colour = " black" ) +
263+ ggplot2 :: geom_bar(data = df %> % dplyr :: mutate(relative_held = dplyr :: if_else(incidental == TRUE , NA , relative_held )), stat = " identity" , position = " identity" , ggplot2 :: aes(x = .data $ feature , y = .data $ relative_held , fill = .data $ category ), na.rm = TRUE ) +
264+ ggplot2 :: geom_bar(data = df %> % dplyr :: mutate(relative_held = dplyr :: if_else(incidental == FALSE , NA , relative_held )),
265+ stat = " identity" , position = " identity" ,
266+ ggplot2 :: aes(x = .data $ feature , y = .data $ relative_held ), na.rm = TRUE , fill = " NA" , colour = " black" ) +
263267 ggplot2 :: labs(title = plotTitle , x = " Feature" , y = " Representation of features \n in total selected area (%)" ) +
264268 ggplot2 :: theme_bw() +
265269 ggplot2 :: scale_y_continuous(limits = c(0 , ymax <- max(df $ relative_held , na.rm = TRUE ) + 10 ), expand = c(0 , 0 )) + # only works for min shortfall without incidental yet
@@ -275,7 +279,9 @@ splnr_plot_featureRep <- function(df,
275279 legend.title = ggplot2 :: element_blank(),
276280 legend.text = ggplot2 :: element_text(size = 16 ),
277281 legend.position = " inside" ,
278- legend.position.inside = c(0.5 , 0.95 ),
282+ # legend.margin = ggplot2::margin(0, 0, 0, 0),
283+ # legend.justification.top = "centre",
284+ legend.position.inside = c(0.5 , 0.92 ),
279285 legend.direction = " horizontal" ,
280286 legend.background = ggplot2 :: element_rect(fill = " NA" ),
281287 title = ggplot2 :: element_text(size = 16 ),
0 commit comments