Order x axis by one then another parameter and plot in ggplot (phyloseq)Change the order of a discrete x scaleplotting melted data.frame with ggplot, does aes(x) need to be a factor?Sorting data on X axisReorder label y axis in ggplotline and point curve using factors in ggplot?Draw lines between two different (“grid.arranged”) plotsggplot/plot in Shiny not workingChange order in which ggplot plots the Y axis variablesPlotting `ggplot` sorted on specific valueggplot sorting axis with flipped coordinates and faceted graphResidual plot with ggplot with X-axis as “ranked” residuals

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Animation: customize bounce interpolation

Identifying "long and narrow" polygons in with PostGIS

What the heck is gets(stdin) on site coderbyte?

Ways of geometrical multiplication

In One Punch Man, is King actually weak?

How to get directions in deep space?

Why would five hundred and five be same as one?

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

Showing mass murder in a kid's book

Limit max CPU usage SQL SERVER with WSRM

Isometric embedding of a genus g surface

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

Proving an identity involving cross products and coplanar vectors

Giving feedback to someone without sounding prejudiced

Deciphering cause of death?

Is there a way to play vibrato on the piano?

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

Do I have to know the General Relativity theory to understand the concept of inertial frame?

ContourPlot — How do I color by contour curvature?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

PTIJ: Which Dr. Seuss books should one obtain?

Why is participating in the European Parliamentary elections used as a threat?



Order x axis by one then another parameter and plot in ggplot (phyloseq)


Change the order of a discrete x scaleplotting melted data.frame with ggplot, does aes(x) need to be a factor?Sorting data on X axisReorder label y axis in ggplotline and point curve using factors in ggplot?Draw lines between two different (“grid.arranged”) plotsggplot/plot in Shiny not workingChange order in which ggplot plots the Y axis variablesPlotting `ggplot` sorted on specific valueggplot sorting axis with flipped coordinates and faceted graphResidual plot with ggplot with X-axis as “ranked” residuals













0















I am trying to graph my phyloseq/deseq2 data output (Log2FoldChange on y and Species name on x) in ggplot and I would like to be able to order them by autotrophs and heterotrophs as well as max-min value. I have a column I added into the Taxa file named "Trophic".



Taxa file snippet



The pipeline turns the phyloseq object into a deseq object, and that is where Log2FoldChange comes in.



deseq output snippet



Then they're combined, which is what I am working with.
(Here is the tutorial if you need more)



I have this code, which I think orders the species by highest to lowest Log2FoldChange and comes out with a graph like this.



x = tapply(sigtab$log2FoldChange, sigtab$Species, function(x) max(x)) 
x = sort(x, TRUE)
sigtab$Species = factor(as.character(sigtab$Species), levels=names(x)


However, I am not exactly sure how to modify this in order to have them sorted first by trophic status and then by species and then plotted as such.



I would basically like to be able to have two "sides" of the same graph (auto then hetero), both ordered from max value to min value of Log2FoldChange.



Could anyone please help me figure this out?










share|improve this question
























  • You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

    – Croote
    Mar 7 at 22:26











  • Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

    – Megan Ladds
    Mar 8 at 3:34











  • See Here for more discussion on reordering factors for plotting

    – Croote
    Mar 8 at 6:00






  • 1





    Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

    – Megan Ladds
    Mar 11 at 18:58
















0















I am trying to graph my phyloseq/deseq2 data output (Log2FoldChange on y and Species name on x) in ggplot and I would like to be able to order them by autotrophs and heterotrophs as well as max-min value. I have a column I added into the Taxa file named "Trophic".



Taxa file snippet



The pipeline turns the phyloseq object into a deseq object, and that is where Log2FoldChange comes in.



deseq output snippet



Then they're combined, which is what I am working with.
(Here is the tutorial if you need more)



I have this code, which I think orders the species by highest to lowest Log2FoldChange and comes out with a graph like this.



x = tapply(sigtab$log2FoldChange, sigtab$Species, function(x) max(x)) 
x = sort(x, TRUE)
sigtab$Species = factor(as.character(sigtab$Species), levels=names(x)


However, I am not exactly sure how to modify this in order to have them sorted first by trophic status and then by species and then plotted as such.



I would basically like to be able to have two "sides" of the same graph (auto then hetero), both ordered from max value to min value of Log2FoldChange.



Could anyone please help me figure this out?










share|improve this question
























  • You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

    – Croote
    Mar 7 at 22:26











  • Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

    – Megan Ladds
    Mar 8 at 3:34











  • See Here for more discussion on reordering factors for plotting

    – Croote
    Mar 8 at 6:00






  • 1





    Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

    – Megan Ladds
    Mar 11 at 18:58














0












0








0








I am trying to graph my phyloseq/deseq2 data output (Log2FoldChange on y and Species name on x) in ggplot and I would like to be able to order them by autotrophs and heterotrophs as well as max-min value. I have a column I added into the Taxa file named "Trophic".



Taxa file snippet



The pipeline turns the phyloseq object into a deseq object, and that is where Log2FoldChange comes in.



deseq output snippet



Then they're combined, which is what I am working with.
(Here is the tutorial if you need more)



I have this code, which I think orders the species by highest to lowest Log2FoldChange and comes out with a graph like this.



x = tapply(sigtab$log2FoldChange, sigtab$Species, function(x) max(x)) 
x = sort(x, TRUE)
sigtab$Species = factor(as.character(sigtab$Species), levels=names(x)


However, I am not exactly sure how to modify this in order to have them sorted first by trophic status and then by species and then plotted as such.



I would basically like to be able to have two "sides" of the same graph (auto then hetero), both ordered from max value to min value of Log2FoldChange.



Could anyone please help me figure this out?










share|improve this question
















I am trying to graph my phyloseq/deseq2 data output (Log2FoldChange on y and Species name on x) in ggplot and I would like to be able to order them by autotrophs and heterotrophs as well as max-min value. I have a column I added into the Taxa file named "Trophic".



Taxa file snippet



The pipeline turns the phyloseq object into a deseq object, and that is where Log2FoldChange comes in.



deseq output snippet



Then they're combined, which is what I am working with.
(Here is the tutorial if you need more)



I have this code, which I think orders the species by highest to lowest Log2FoldChange and comes out with a graph like this.



x = tapply(sigtab$log2FoldChange, sigtab$Species, function(x) max(x)) 
x = sort(x, TRUE)
sigtab$Species = factor(as.character(sigtab$Species), levels=names(x)


However, I am not exactly sure how to modify this in order to have them sorted first by trophic status and then by species and then plotted as such.



I would basically like to be able to have two "sides" of the same graph (auto then hetero), both ordered from max value to min value of Log2FoldChange.



Could anyone please help me figure this out?







r sorting ggplot2 phyloseq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 4:41









Pikachu the Purple Wizard

2,02761329




2,02761329










asked Mar 7 at 22:03









Megan LaddsMegan Ladds

1




1












  • You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

    – Croote
    Mar 7 at 22:26











  • Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

    – Megan Ladds
    Mar 8 at 3:34











  • See Here for more discussion on reordering factors for plotting

    – Croote
    Mar 8 at 6:00






  • 1





    Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

    – Megan Ladds
    Mar 11 at 18:58


















  • You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

    – Croote
    Mar 7 at 22:26











  • Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

    – Megan Ladds
    Mar 8 at 3:34











  • See Here for more discussion on reordering factors for plotting

    – Croote
    Mar 8 at 6:00






  • 1





    Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

    – Megan Ladds
    Mar 11 at 18:58

















You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

– Croote
Mar 7 at 22:26





You can arrange in order with dplyr::arrange() and you can specify whether you want it in desc order otherwise it will be ascending by default. arrange(data, first, desc(second)) etc.

– Croote
Mar 7 at 22:26













Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

– Megan Ladds
Mar 8 at 3:34





Oh marvelous! So that worked and I was able to correctly order my actual data frame, but when I plot it the species names are still in alphabetical rather than being in the order I just put them in. Is there a special thing I would need to add in order to keep it like that (as in non-alphabetical) for the graph?

– Megan Ladds
Mar 8 at 3:34













See Here for more discussion on reordering factors for plotting

– Croote
Mar 8 at 6:00





See Here for more discussion on reordering factors for plotting

– Croote
Mar 8 at 6:00




1




1





Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

– Megan Ladds
Mar 11 at 18:58






Thank you so much for your help. I was able to fix the graph using this sigtab<-arrange (sigtab, Trophic, desc(log2FoldChange)) sigtab$Species <- factor(sigtab$Species, levels = sigtab$Species)

– Megan Ladds
Mar 11 at 18:58













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053515%2forder-x-axis-by-one-then-another-parameter-and-plot-in-ggplot-phyloseq%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053515%2forder-x-axis-by-one-then-another-parameter-and-plot-in-ggplot-phyloseq%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived