sachsmc / ggkm

Compute and display Kaplan-Meier Curves with ggplot2
Other
22 stars 4 forks source link

Logical status leads to strange plot #5

Open jenzopr opened 8 years ago

jenzopr commented 8 years ago

Hi Michael,

when using a logical status in geom_kmticks like

library(ggkm)
data(lung)
lung$status2 = ifelse(lung$status == 1, TRUE, FALSE)
ggplot(lung, aes(time = time, status = status2)) + geom_km() + geom_kmticks()

ggkm_logical_status_1 the ticks land on a straight line located at y=1. I have to use the code

ggplot(lung, aes(time = time, status = as.numeric(status2))) + geom_km() + geom_kmticks()

to fix this. Can you replicate the behavior or is the effect because of an older ggplot2 version?

sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggkm_0.3.0      scales_0.4.0    survival_2.38-3 ggplot2_2.1.0  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3      digest_0.6.9     withr_1.0.1      grid_3.2.3       R6_2.1.2         plyr_1.8.3      
 [7] gtable_0.2.0     git2r_0.14.0     httr_1.1.0       curl_0.9.6       labeling_0.3     splines_3.2.3   
[13] devtools_1.10.0  tools_3.2.3      munsell_0.4.3    colorspace_1.2-6 memoise_1.0.0

Nevertheless, thanks for the great package! It helps a lot! Jens

sachsmc commented 8 years ago

This is a known issue. It has something to do with how ggplot creates groups for logical and character aesthetics. I am looking into it but haven't found a solution yet.

For now, it's best to convert your status variable to numeric.

Thanks!