-1

I want to change (place) in the list to 1 Europe, 2 Asia, 3 Africa, 4 Latin America, and 5 North America. so I can have names on the plot rather than numbers.

What I have so far:

What I have so far

  • 2
    Please don't post data as images. Take some time to read [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Rui Barradas Aug 25 '18 at 11:36

1 Answers1

0

I think I didn't understand your question correctly at first. If you want to replace the values in a column with character strings and then use them in alphabetic order in ggplot you could try for example:

library(tidyverse)
last %>% 
  mutate(place = forcats::fct_recode(place %>% as.character(),
                                   'Europe' = '1',
                                   'Asia' = '2',
                                   'Africa' = '3',
                                   'Latin America' = '4',
                                   'North America' = '5') %>% as.character())

And then use the place in facet_grid. It should wrap them in alphabetic order. See this reproducable version of it:

library(tidyverse)
mtcars %>% 
  mutate(am = forcats::fct_recode(am %>% as.character(), 
                         'Africa' = '1', 
                         'Europe' = '0') %>% as.character()) %>% 
  ggplot(aes(cyl, mpg)) +
  geom_point() +
  facet_grid(~am)

Does this work as you intented?

mkeskisa
  • 86
  • 4
  • i provide you with an image that may help to understand the problem, i'm new to R. However, in the third column contain (1,2,3,4,5) for all of the world countries displayed by alphabetic order. – Mohamed Hachaichi Aug 25 '18 at 11:05
  • I think I misunderstood your question originally. I edited the answer so the names are in alphabetic order. – mkeskisa Aug 25 '18 at 11:38
  • i have this list as follow: V1 V2 V62 place 1 Aruba ABW 0.42078068 1 2 Afghanistan AFG 2.49078956 2 3 Angola AGO 3.31350733 3 4 Albania ALB -0.09197229 1 5 Andorra AND -0.40973567 1 6 Armenia ARM 0.19244221 2 – Mohamed Hachaichi Aug 25 '18 at 12:21