How to chart in r with variable titles?

Asked

Viewed 88 times

2

I need to create a function that returns graphics in which the title name contains the variable name, as in the example.

Dados<-c(5,4,8,9,2,1,6,2,5)

Validação <- function(y){
  plot(y, main='Gráfico y')
 }

Validação(Dados)

the result should be a chart with title "Data Chart"

1 answer

5


To get the variable’s real name you need to use deparse(substitute(y)) in the title of the chart:

Validação <- function(y){
  plot(y, main= paste('Gráfico', deparse(substitute(y))))
}

This goes so far for the package graphics base, as for the ggplot2 and lattice...

  • It worked. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.