Skip to content
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

Manual label order in combmatrix #20

Open
Rekyt opened this issue Dec 9, 2020 · 4 comments
Open

Manual label order in combmatrix #20

Rekyt opened this issue Dec 9, 2020 · 4 comments

Comments

@Rekyt
Copy link

Rekyt commented Dec 9, 2020

Hi @const-ae 👋 ,
Thank you so much for the ggupset package, I think it really helps to visualize categorical data!
I've looked at previous issues and couldn't find an answer to my question:
Is there an easy way to set the order of the y axis in the combmatrix?
InkedRplot_LI

It seems that changing factor levels doesn't affect at all the row orders of the comb matrix. I thought it was only due to ordering by frequency but it does not seem to be only driven by frequency. From what I understood looking at the code the order is set at these lines:

ggupset/R/axis_combmatrix.R

Lines 181 to 182 in d379fb5

labels <- factor(panel_params$x.labels, levels = panel_params$x.labels, ordered=TRUE)
labels_split <- strsplit(panel_params$x.labels, self$sep)

Would it be possible to have the user provide a custom order in place of the one created in labels_split?

Thanks again for the great package!

@const-ae
Copy link
Owner

const-ae commented Dec 9, 2020

Hi Matthias,

thanks for the thoughtful issue. What you suggest sounds like a useful feature. However I am afraid, that I don't have the capacity to implement this myself. But I would be happy to accept and review a pull request.

Best,
Constantin

@Rekyt
Copy link
Author

Rekyt commented Dec 9, 2020

Hi Constantin,
Thank you for your very quick answer.
I'll try proposing a PR if I can wrap my head around a good solution.

@const-ae
Copy link
Owner

const-ae commented Dec 9, 2020

Thanks. If you have any question, feel free to ask :)

@tjiyyanki1
Copy link

factor_levels = c() #provide your own levels

upset_overriding_fn = function(df) {
df %>%
mutate(single_label = factor(single_label,levels = factor_levels ) ) %>%
ggplot(aes(x = at, y = single_label)) +
geom_rect(aes(fill= index %% 2 == 0), ymin=df$index-0.5,
ymax=df$index+0.5, xmin=0, xmax=1) +
geom_point(aes(color= observed), size = 3) +
geom_line(data= function(dat) dat[dat$observed, ,drop=FALSE],
aes(group = labels), size= 1.2) +
ylab("") + xlab("") +
scale_x_continuous(limits = c(0, 1), expand = c(0, 0)) +
scale_fill_manual(values= c(TRUE = "white", FALSE = "#F7F7F7")) +
scale_color_manual(values= c(TRUE = "black", FALSE = "#E0E0E0")) +
guides(color="none", fill="none") +
theme(
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.length = unit(0, "pt"),
axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.line = element_blank(),
panel.border = element_blank()
)
}

When plotting:
pt1 +
axis_combmatrix(sep = "," ,override_plotting_function = upset_overriding_fn )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants