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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page