Closed xlea23 closed 1 year ago
geom_col_pattern()
with numeric x values (instead of say factor values). For some reason it looks like in this case we are drawing the patterns in a different (wider) region than the color fills. This doesn't seem to be connected to the pattern repeating and is observed when we don't have repeated patterns.library(ggplot2)
library(ggpattern)
df <- data.frame(trt = c("a", "b"),
x = c(0.08, 0.39),
y = rep(1, 2))
df %>%
ggplot(aes(x = x, y = y)) +
geom_col_pattern(aes(pattern = trt, fill = trt),
color = NA,
show.legend = TRUE,
position = "fill",
width = 3) +
scale_pattern_manual(
values = c("a" = "stripe", "b" = "circle", "c" = "none"))
Nota bene: @xlea23 if you just need to draw rectangles with numeric x and y axes then geom_rect_pattern()
seems to currently be working correctly and (with a bit of work) should be able to produce the targeted chart...
geom_*_pattern()
call {ggpattern}
first draws the polygon fill colors, then the patterns, and then the polygon borders. In your case the green "S" column (with stripes) overlaps with the right pink "NA" column (with no pattern). The pink fill covers up the green fill and then nothing covers up the stripe and then you instructed fully transparent polygon borders...ggplot2::geom_col()
with alpha = 0.5
to show this overlap occurs in base {ggplot2}
...library(ggplot2)
df <- data.frame(
study_id = c(3, 3, 3, 3), primary_therapy = c("Si", "Si", "Si", "Si"),
additional_therapy = c("NA", "S", "NA", "V+S"), end_yr = c(0.08, 0.39, 3.03, 3.4))
df %>%
ggplot(aes(x = end_yr, y = study_id)) +
geom_col(aes(fill = additional_therapy),
color = NA,
show.legend = TRUE,
position = "fill",
width = 3,
alpha = 0.5)
Bug description
Using ggpattern package in R, how can I not show a pattern for "NA" values but then have patterns continue after that point? When I run this code, there are no more patterns after an "NA" value even though there should be. There is a problem with ggpattern when it comes to repeating patterns.In the below code, you can see that fill acts appropriately, but pattern will never repeat twice, which causes the pattern from "S" to split over into the second red bar, which shouldn't have any pattern because it's "NA". See more information here.
Minimal, reproducible example
Session info
Please enter here the results of
xfun::session_info("ggpattern")