-1

I get this plot out of my data

enter image description here

and I am trying to have the points sorted descendingly (fist = highest; last = lowest).I tried reorder as well as mutate with my code but with no success.

ggplot(my_data, aes(x = Team, y = Days)) +
  geom_point(aes(color = factor(Country))) + facet_wrap( ~ Country, ncol = 2)

The data files (xls) looks like this:

Country Team    Days
England Arsenal FC  1.495
England Aston Villa 851
England Brighton & Hove Albion  1.125
England Burnley FC  1.181
England Chelsea FC  1.061
England Crystal Palace  781
England Everton FC  1.275
Frankreich  AS Monaco   714
Frankreich  AS Saint-Étienne    859
Frankreich  Angers SCO  809
Frankreich  Dijon FCO   938
Frankreich  FC Lorient  1.071
Frankreich  FC Metz 717
Frankreich  FC Nantes   856

Any idea how to code this? Thx!

TomTe
  • 193
  • 9
  • 3
    Provide `my_data` in `dput()` format. Please visit [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – UseR10085 Sep 02 '20 at 10:16
  • Without your data, it's hard to know for sure if this will work, but a simple thing to try is `scale_y_reverse()` – Ben Norris Sep 02 '20 at 10:27

2 Answers2

0

I found the solution with this little twist

geom_point(aes(reorder(Team, Days, mean)
TomTe
  • 193
  • 9
0

Is this what you are looking for?

library(tidyverse)

df <- tribble(
  ~Country, ~Team,    ~Days,
  'England', 'Arsenal FC',  1495,
  'England', 'Aston Villa', 851,
  'England', 'Brighton & Hove Albion',  1125,
  'Frankreich',  'AS Monaco',   714,
  'Frankreich',  'AS Saint-Étienne',    859,
  'Frankreich',  'Angers SCO',  809
)


ggplot(df,aes(Days,reorder(Team,Days),color = Team)) + 
  geom_point()

ggplot(df,aes(Days,reorder(Team,-Days),color = Team)) + 
  geom_point()

# I would go with geom_col
ggplot(df,aes(Days,reorder(Team,Days),fill = Country)) + 
  geom_col() + 
  labs(y = '')

enter image description here

Magnus Nordmo
  • 923
  • 7
  • 10