ggplot2 - possible to reorder x's by value of computed y (stat_summary)?

后端 未结 1 1419
孤独总比滥情好
孤独总比滥情好 2021-01-07 06:03

Is it possible to reorder x values using a computed y via stat_summary? I would think that this should work:

stat_summary( aes( x = reorder( XVarName , ..y..         


        
相关标签:
1条回答
  • 2021-01-07 06:28

    I've seen a number of your posts, and I think this may be helpful for you. When generating a plot, always save it to a unique variable

    Create your plots without regard for ordering at first, until you're comfortable just creating the plots. Then, work your way into the structure of the ggplot objects to get a better understanding of what's in them. Then, figure out what you should be sorting.

    plot1 <- ggplot() + ...
    

    You can push plots to the viewport by typing out the object name that you've saved them to:

    plot1
    

    Creating a ggplot object (or variable) allows you the opportunity to review the structure of the plot. Which, incidentally, can answer a number of the questions that you've been having so far.

    str(plot1)
    

    It is still fairly simple to reorder a plot after you've saved it as a variable/object, albeit with slightly longer names:

    plot$data$variable_tobe_recoded <- factor(...)
    
    0 讨论(0)
提交回复
热议问题