0

I have a dataset with countries variables as such

location      population        vax
Canada           38067913        345
China           1444216102      3245
Mexico          130262220       5234

I thought i could write something like :

plot <- ggplot(df, aes(x=location,y= vax)+
    geom_bar(stat="identity")+
   theme(axis.text.x = element_text(location + population))

my plot on the X axis should write : Canada 38067913, China 1444216102, Mexico 130262220

thank you

1
  • The "+" function cannot handle character values in R. (You should post all the error messages you get, and I'm pretty sure you got one.) Commented Dec 18, 2021 at 2:57

1 Answer 1

3

You can paste the two columns -

library(ggplot2)

ggplot(df, aes(x= paste(location, population) ,y= vax)) + 
  geom_col() + 
  xlab('Location')

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

but what if it's already ordered like this aes(x=reorder(location,vax)
You can change that to aes(x= reorder(paste(location, population),vax)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.