You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The scale_xfill_manual() does not seem to work as expected for a categorical factor when the argument drop = FALSE is set. Here is a simple, reproducible example where I create a series that can take random values between 5 and 50. I create 3 categories for binning the y-values where the first 2 will obviously capture all values in the series and then intentionally created the 3rd category to capture values above 50 (which cannot happen) and will help illustrate the issue.
library(tidyverse)
library(ggside)
library(RColorBrewer)
set.seed(1234)
df <- tibble(
x = 1:20,
y = runif(n = 20, 5, 50)
) %>%
mutate(
class = case_when(
y <= 20 ~ "Category 1",
y > 20 & y <= 50 ~ "Category 2",
y > 50 ~ "Category 3"
),
class = factor(class, levels = paste("Category", 1:3))
)
pal <- brewer.pal(n = 3, name = "Dark2")
ggplot(data = df) +
theme_bw() +
geom_line(aes(x = x, y = y)) +
scale_y_continuous(
limits = c(0, 60),
expand = c(0, 0)
) +
geom_xsidetile(aes(xfill = class, x = x, y = "Dummy class")) +
scale_xsidey_discrete() +
scale_xfill_manual(
values = pal,
name = "Classification",
drop = FALSE
) +
ggside(x.pos = "bottom") +
theme(legend.position = "bottom")
Here is the resulting graph when using geom_xsidetile():
As you can see, the label for Category 3 shows in the legend, but the color (which should be purple with the Dark2 color palette) does not. Please keep in mind that this is just a toy example to illustrate the issue. This can cause a problem if you are creating many plots at once for a large number of time series where not every series will necessary take on all possible categories.
The text was updated successfully, but these errors were encountered:
The
scale_xfill_manual()
does not seem to work as expected for a categorical factor when the argumentdrop = FALSE
is set. Here is a simple, reproducible example where I create a series that can take random values between 5 and 50. I create 3 categories for binning the y-values where the first 2 will obviously capture all values in the series and then intentionally created the 3rd category to capture values above 50 (which cannot happen) and will help illustrate the issue.Here is the resulting graph when using
geom_xsidetile()
:As you can see, the label for Category 3 shows in the legend, but the color (which should be purple with the Dark2 color palette) does not. Please keep in mind that this is just a toy example to illustrate the issue. This can cause a problem if you are creating many plots at once for a large number of time series where not every series will necessary take on all possible categories.
The text was updated successfully, but these errors were encountered: