0

I'm trying a different method to boxplot two population means.I'm using reshape2's melt function which comes inbuilt with 2 columns, variable and value. Below is the code. It works but I get a warning that

  plot.Rttest: no visible binding for global variable 'variable'
  plot.Rttest: no visible binding for global variable 'value'

Code -

#' Generic plot function that plots the population mean difference and its confidence interval
#'
#' @param x object that has the data
#' @param ... generic plot functions uses this argument so when overloading, it is needed
#'
#' @return returns a boxplot of both populations to see if their means are same of different or how far off
#' @importFrom ggplot2 aes geom_boxplot ggplot labs
#' @importFrom reshape2 melt
#' @examples
#' \dontrun{
#' plot(obj)}
#' @export
plot.Rttest <- function(x, ...){
  w <- x[["data"]][["x"]]
  v <- x[["data"]][["y"]]
  df <- data.frame(w,v)
  data_long = melt(df)

  ggplot(data_long, aes(x=variable,y=value,fill =variable)) + geom_boxplot() +
    labs(x="Population", y= "Samples")

}

I use roxygen2 to create the namespaces and skeleton. When I try to generate a skeleton, the variable and value don't appear but the warning is bothersome. I checked the documentation and couldn't find a way. If anyone can help me figure this out, I'd appreciate it!

  • in your ggplot try to add .data$variable and .data$value where variable and value are – Mike Apr 28 '23 at 13:14
  • I tried ggplot(data_long, aes(x=.data$variable,y=.data$value,fill =.data$variable)) + geom_boxplot() + labs(x="Population", y= "Samples") didn't work. I even tried .data_long$variable. Still got a warning – Jasmin Wilson Apr 28 '23 at 13:31
  • ok then I would try either putting the variable names in quotes or something like: data_long[["variable"]] – Mike Apr 28 '23 at 13:45

1 Answers1

1

Mike answered in the comments, just wanted to make a note.

ggplot(data_long, aes(x=.data_long[[variable]],y=.data_long[[value]],fill =.data_long[[variable]])) + geom_boxplot() + labs(x="Population", y= "Samples")

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 03 '23 at 02:34