When using geom_ribbon()
with the shape aesthetic, there appears to be a difference in the opacity on the shaded area creating blocks in the region.
I have recreated the problem where I identified that these opacity changes are only present when the shape aesthetic is included.
Data set up:
alpha <- c("A","B","C","D", "E", "F", "G")
percent <- c(0.012, -0.02, 0.015, -0.01, 0.89, 0.12, -0.25)
flow <- c(-5, 2, -3, 3, 1, 4, -2)
shape <- c("D", "D", "L", "L", "L", "D", "L")
df <- data.frame(alpha,percent,flow, shape)
x_min = min(df$percent)
x_min = round(x_min/0.01)*0.01 - 0.01
x_max = max(df$percent)
x_max = round(x_max/0.01)*0.01 + 0.01
y_min = min(df$flow)
y_min = round(y_min)
y_max = max(df$flow)
y_max = round(y_max)
n_row = nrow(df)
Chart with no shape aesthetic, geom_ribbon() works:
df %>%
ggplot(aes(x = percent, y = flow, label = alpha)) +
geom_point() +
geom_text_repel(show.legend = FALSE, size = 3) +
scale_size_continuous(labels = scales::percent) +
theme_bw() +
scale_x_continuous(labels = scales::percent_format(accuracy = 0.1L)) +
scale_y_continuous(labels = scales::dollar_format(negative_parens = TRUE, suffix = "m")) +
geom_ribbon(aes(x = seq(x_min, x_max + 0.01, length.out = n_row), ymin = 0, ymax = y_max), alpha = 0.04, linetype = 0, show.legend = FALSE, fill = "green") +
geom_ribbon(aes(x = seq(x_min, x_max + 0.01, length.out = n_row), ymin = y_min, ymax = 0), alpha = 0.04, linetype = 0, show.legend = FALSE, fill = "red")
Chart with shape aesthetic, geom_ribbon() seems not to work:
df %>%
ggplot(aes(x = percent, y = flow, label = alpha, shape = shape)) +
geom_point() +
geom_text_repel(show.legend = FALSE, size = 3) +
scale_size_continuous(labels = scales::percent) +
theme_bw() +
scale_x_continuous(labels = scales::percent_format(accuracy = 0.1L)) +
scale_y_continuous(labels = scales::dollar_format(negative_parens = TRUE, suffix = "m")) +
geom_ribbon(aes(x = seq(x_min, x_max + 0.01, length.out = n_row), ymin = 0, ymax = y_max), alpha = 0.04, linetype = 0, show.legend = FALSE, fill = "green") +
geom_ribbon(aes(x = seq(x_min, x_max + 0.01, length.out = n_row), ymin = y_min, ymax = 0), alpha = 0.04, linetype = 0, show.legend = FALSE, fill = "red")