Novartis / xgxr

R package for supporting exploratory graphics at http://opensource.nibr.com/xgx
Other
13 stars 7 forks source link

xgx_annotate_status does not work for special datatypes #41

Closed margoal1 closed 11 months ago

margoal1 commented 3 years ago

Describe the bug Error using xgx_annotate_status when x or y is of datatype "Date"

To Reproduce library(ggplot2) library(xgxr)

dummy_data <- data.frame(x = as.Date(c("2015-01-01", "2016-01-01")), y = c(1,2)) ggplot(dummy_data, aes(x = x, y = y)) + geom_point() + xgx_annotate_status("DRAFT")

Error: Invalid input: date_trans works with objects of class Date only

Expected behavior Should display plot with "DRAFT" label in upper right hand corner

Package versions (please complete the following information):

Additional context May also need to check on a variety of other data types. Could include within the function something like xmax = max(na.omit(x)) in order to get the max x value for placement of the draft label.

margoal1 commented 3 years ago

There is a workaround:

library(ggplot2) library(xgxr) xmax <- max(na.omit(dummy_data$x)) ggplot(dummy_data, aes(x = x, y = y)) + geom_point() + xgx_annotate_status("DRAFT", x = xmax)

Maybe can use this as a starting point for how to fix the function.

iamstein commented 3 years ago

Thanks for finding this issue @margoal1. Do you know how you access the X variable of the current ggplot object within the xgx_annotate_status() function? I thought maybe with your experience with ggprotos from the other functions, you might know how.

margoal1 commented 3 years ago

The only way I know off the top of my head would be to rewrite using the ggproto definition underlying the ggplot2 annotate function. Then there's a part of the ggproto object, I think called data, where you can manipulate the data.

iamstein commented 11 months ago

Added an example in version 1.1.4 to the function.