Home > other >  How should I atribute names to a list, to work with ggplot function?
How should I atribute names to a list, to work with ggplot function?

Time:12-18

I created a list of lists, each one representing one variable by doing this

names(needed_data) <- c(
  "Ano", "Casamentos Hungria", "Casamentos Eslovénia",
  "Casamentos Noruega", "Divórcios Hungria", 
  "Divórcios Eslovénia","Divórcios Noruega"
)

Then I proceeded to use needed_data in a ggplot function, but when I write, for example aes(x = "Ano", y = "Casamentos Hungria") I don't think R-Studio "understands" this code. How should I name the list, so that it works.

CodePudding user response:

aes() uses tidy evaluation - try either

aes(x = Ano, y = `Casamentos Hungria`)

or

aes_string(x = "Ano", y = "`Casamentos Hungria`")
  • Related