1

could you tell me how to order stacked charts from top to down by sales in 2020? For instance, in 2020 sales were the highest in the 9nth category, so I want to be in this category at the top and so on. In addition, I need to round up years (2012.5 to 2012) I set them as Integer but does not work. used code:

ggplot(data, aes(x=Year, y=Sale, fill=group)) + 
    geom_area()

enter image description here

  • 2
    As I'm not sure what's the issue I deleted my answer. Maybe you could provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Apr 29 '22 at 16:06
  • Could you provide some code to reproduce what you want? – Le Paul Apr 29 '22 at 18:01
  • For me to know, you want to round '.5' values to the nearest lowest value, as you said '2012.5' to '2012' but what if you have '2012.6' it's gonna be '2012' or '2013'? – Le Paul Apr 29 '22 at 18:03

1 Answers1

0

If you want to set 2012.5 or higher (example: 2012.9) to 2012 you just simple use the trunc() function this will cut the decimal and keep you the entire value, in this sense you'll only have the 2012

#try:
trunc(2.2)
trunc(2.5)
trunc(2.99999999)

You can use floor() as well:

#try
floor(2.2)
floor(2.5)
floor(2.999999999)

so insted of using int() for years try one of this built-in functions.

Le Paul
  • 67
  • 8