-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong categorical color range when "legend_interactive = FALSE" #43
Comments
Hey @yvesmauron! Can you take a look at this bug in the next few days? |
It seems that the value ranges of occupancy per occupancy_cat overlap. Is this intended/possible in the
Nonetheless, there seems to be still a small issue with the current logic when ranges are not evenly balanced. So for example, evenly distributed z values per category as shown below work without issue:
However, if ranges are uneven, the legend is off as min/max values of z do not align with the legend:
We need to investigate the best option to fix this; such as e.g. drawing the ranges of the legend based on ranges of values per category in the dataset or other options. Possible solutions will be posted in this thread in the following weeks. |
Hey @yvesmauron! Also the values of library(catmaply)
library(dplyr)
data("vbz")
df <- vbz[[3]]
df %>%
group_by(occ_category,
vehicle) %>%
summarize(
min_occupancy = min(occupancy),
max_occupancy = max(occupancy)
)%>%
ungroup()%>%
arrange(vehicle)
Adding the category ( The mentioned Issue from @SimonSchuepbach depends on the switch between Let's try with this one. df_test <- tibble(
x=as.integer(c(1,1,1,1,2,2,2,2)),
y=as.integer(c(1,2,3,4,1,2,3,4)),
z=as.integer(c(1,3,5,11,1,3,5,11)),
z_cat=as.integer(c(1,3,5,11,1,3,5,11)),
z_cat_name=as.character(c(1,3,5,11,1,3,5,11))
)
catmaply(
df_test,
x=x,
y=y,
z=z,
categorical_color_range = TRUE,
color_palette = viridis::inferno,
categorical_col = z_cat,
legend_interactive = TRUE,
legend_col = z_cat_name,
x_range = 2
) '5' is one of the orange colors, looks like expected VS. df_test <- tibble(
x=as.integer(c(1,1,1,1,2,2,2,2)),
y=as.integer(c(1,2,3,4,1,2,3,4)),
z=as.integer(c(1,3,5,11,1,3,5,11)),
z_cat=as.integer(c(1,3,5,11,1,3,5,11)),
z_cat_name=as.character(c(1,3,5,11,1,3,5,11))
)
catmaply(
df_test,
x=x,
y=y,
z=z,
categorical_color_range = TRUE,
color_palette = viridis::inferno,
categorical_col = z_cat,
legend_interactive = FALSE,
legend_col = z_cat_name,
x_range = 2
) '5' is not in the orange colors, but i would expect it there. |
Describe the bug
When plotting with a categorical color range and no interactive legend ("legend_interactive = FALSE"), the color range is biased, some values appear as if they belong to a different category than they actually are in.
Thanks for considering the issue.
I'll be ready for eventual questions.
Cheers, Simon
To Reproduce
To reproduce you can use the available "vbz" data.
The code to reproduce is given below. Execute it onec as it is and an other time with the option "legend interactive = TRUE":
data("vbz")
df <- vbz[[3]]
catmaply(
df,
x = trip_id,
x_order = trip_seq,
y = stop_name,
y_order = stop_seq,
z = occupancy,
categorical_color_range = TRUE,
categorical_col = occ_category,
legend_interactive = FALSE,
hover_template = paste(
"Time:", departure_time,
"
Stop:", stop_name,
"
Occupancy:", occupancy,
"
Occupancy Category:", occ_cat_name,
"
No Of Measurements:", number_of_measurements,
""
),
legend_col = occ_cat_name
)
Expected behavior
I would expect the colors in the plot to stay the same for each square within the heatmap plot, since neither the values nor their categories change. It's just the legend type which changes. Instead, the colors are shifted such that for some of the squares the category seems to change, which is not true.
With the interactive legend the color category and the variable category seem to match, whereas with the non-interactive legend, they seem to be offset.
Screenshots
Screenshot of a non-interactive example, where a square (courseno.: 17020, station name: Zuerich, Kreuzplatz) with a value of the category "medium high" appears in a color which clearly is within the color palette of the category "high":
The very same example but this time with the interactive legend shows, that the same square now belongs to the correct category "medium high":
Environment:
Append result of
sessionInfo()
.sessionInfo.txt
The text was updated successfully, but these errors were encountered: