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

Remove x-axis labels with independent = "x" if they are identical #155

Closed
DanaBlu opened this issue Apr 11, 2024 · 4 comments
Closed

Remove x-axis labels with independent = "x" if they are identical #155

DanaBlu opened this issue Apr 11, 2024 · 4 comments

Comments

@DanaBlu
Copy link

DanaBlu commented Apr 11, 2024

Hey @teunbrand,

thank you for your great package!

I was wondering if there is an option to use the remove_labels="x" option together with independent="x" from facet_grid2, if the labels are identical.

I will describe my issue from the very beginning:

I'm working with comp_barplot from the microVIZ package (https://github.com/david-barnett/microViz) and I encountered a problem when using facet_grid from ggplot2. Each x-axis label was repreated four times, but three times without the corresponding data plotted.

comp_barplot(phy.merged.rep, tax_level = "Phylum", n_taxa = 11, label = "sample_short", sample_order = sample_names(phy.merged.rep)) +
facet_grid(id ~ racon, scales = "free") +
theme_bw() +
theme(panel.grid.major = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
axis.title.y = element_text(size = 10, vjust = 3, face = "plain")) +
guides(col = FALSE, shape = guide_legend(override.aes = list(size = 2.5)))

V9_phylum_wrong

Then I found your package and was able to only plot the data on the x-axis were data points are actually available with the independent="x" option.

comp_barplot(phy.merged.rep, tax_level = "Phylum", n_taxa = 11, label = "sample_short", sample_order = sample_names(phy.merged.rep)) +
facet_grid2(id ~ racon, scales = "free", independent="x") +
theme_bw() +
theme(panel.grid.major = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
axis.title.y = element_text(size = 10, vjust = 3, face = "plain")) +
guides(col = FALSE, shape = guide_legend(override.aes = list(size = 2.5)))

V9_phylum

Now I would like to get rid of the x-axis labels and only display them at the outer margins (remove_labels="x"), as the labels are identical anyways. However, I learned that remove_labels cannot be used together with independent.

Is there any solution for me to get rid of the identical x-axis labels?

Best,

Dana

@teunbrand
Copy link
Owner

Hi there, thanks for the report! Could you give a minimal reprocible example? At the time of writing, I'm too tired to go through the source code of comp_barplot() to see where the problem might originate.

@DanaBlu
Copy link
Author

DanaBlu commented Apr 12, 2024

Thank your for your fast reply!

So here are my example sample_data, taxa_table and otu_table.

inf_test.csv
tax_test.csv
otu_test.csv

I have created the phyloseq object and the taxonomy representation as follows:

phy.info <- sample_data(inf)
phy.otu <- otu_table(t(otu), taxa_are_rows=T)
phy.taxonomy <- tax_table(as.matrix(tax))
phy <- phyloseq(phy.otu, phy.taxonomy, phy.info)

comp_barplot(phy, tax_level = "Phylum", n_taxa = 11, label = "inf.sample_short", sample_order = sample_names(phy)) +
facet_grid2(inf.id ~ inf.racon, scales = "free") +
theme_bw() +
theme(panel.grid.major = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
axis.title.y = element_text(size = 10, vjust = 3, face = "plain")) +
guides(col = FALSE, shape = guide_legend(override.aes = list(size = 2.5)))

plot_test

@teunbrand
Copy link
Owner

Sorry for bothering with this again, but can this problem be shown with just base R + ggplot2 + ggh4x?
I'm aim to have ggh4x broadly compatible with ggplot2 and its extension systems, but I cannot guarantee compatibility with every function that wraps ggplot2 like comp_barplot().

@DanaBlu
Copy link
Author

DanaBlu commented Jun 28, 2024

Hello @teunbrand,
the problem has already been solved! Sorry, I completely forgot to close the topic!
By adding x=sample_short the problem is gone. So ggplot2 + gg4hx + comp_barplot are all compatible with each other.
Thank you for your support, I will close this issue now.
Best,
Dana

@DanaBlu DanaBlu closed this as completed Jun 28, 2024
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

2 participants