vendredi 15 février 2019

R - How to make if-else statements in functions?

I have this function which gives me a plot:

myfunction <- function( data_ )

  {
  ggplot( data_,
      aes(y = data_$Freq, axis1 = data_$a1, axis2 = data_$a2, axis3 = data_$a3,axis4 = data_$a4, axis5 = data_$a5, axis6 = data_$a6, axis7 = data_$a7, axis8 = data_$a8)) +
geom_alluvium(aes(fill = data_$a1), width = 1/12) +
geom_stratum(width = 1/12, fill = "black", color = "grey") +
geom_label(stat = "stratum", label.strata = TRUE) +
scale_x_discrete(limits = c ("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8"), expand = c(0.02, 0.02)) + 
scale_fill_brewer(type = "qual", palette = "Set1") +
ggtitle("CLL")


}
  myfunction(data_= as.data.frame(allu))

I want to include an if-statement in the function which says: if limits is above a8 then it will go false or else true. Is this possible?

Aucun commentaire:

Enregistrer un commentaire