sinhrks / ggfortify

Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
Other
525 stars 65 forks source link

Remove label legend #191

Closed obenno closed 6 years ago

obenno commented 6 years ago

Hi,

Thanks for the amazing package. Is there a way to remove label legend which is a small "a" in ggforty? Some parameters to work as geom_text(show.legend=F)? Thanks.

Bests, oben

terrytangyuan commented 6 years ago

Thanks for the issue. Could you give a minimal example?

obenno commented 6 years ago

Thanks for reply.

For pca plots, I would like to achieve a plot like

pca.value <- as.data.frame(prcomp(iris[-5])$x)
ggplot(cbind(pca.value, iris[5]), aes(PC1, PC2, color=Species))+geom_point()+geom_text(aes(label=rownames(iris)), show.legend=F)

legend without tiny a of geom_text. Thanks.

terrytangyuan commented 6 years ago

I am not sure what you meant. The following code could produce similar plots:

library(ggfortify)
autoplot(prcomp(iris[-5]), data = iris, colour = 'Species', label = TRUE)

Is this what you need?

obenno commented 6 years ago

Sorry for the confusing codes, which I mean is

With "a" Without "a"

terrytangyuan commented 6 years ago

Thanks. But I never saw those a's for some reason. Perhaps something's wrong with your ggplot2 version?

obenno commented 6 years ago

Sorry for the late reply. My sessioninfo is

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_HK.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_HK.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_HK.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] ggfortify_0.4.3 ggplot2_2.2.1  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12     tidyr_0.6.3      dplyr_0.7.2      assertthat_0.2.0
 [5] grid_3.4.2       plyr_1.8.4       R6_2.2.2         gtable_0.2.0    
 [9] magrittr_1.5     scales_0.4.1     stringi_1.1.5    rlang_0.1.1     
[13] lazyeval_0.2.0   bindrcpp_0.2     tools_3.4.2      stringr_1.2.0   
[17] glue_1.1.1       munsell_0.4.3    compiler_3.4.2   pkgconfig_2.0.1 
[21] colorspace_1.3-2 bindr_0.1        gridExtra_2.3    tibble_1.3.3

It seems that this also occurs in your cran tutorial for iris data. Could you also share your sessioninfo? Might be internal problem or locale setting? Thanks.

terrytangyuan commented 6 years ago

Thanks! Seems like the following two plots indeed seem problematic and I could reproduce the problem:

df <- iris[c(1, 2, 3, 4)]
autoplot(prcomp(df), data = iris, colour = 'Species', shape = FALSE, label.size = 3)
autoplot(prcomp(df), data = iris, colour = 'Species', label = TRUE, label.size = 3)
obenno commented 6 years ago

Thanks~

terrytangyuan commented 6 years ago

I just pushed an update (install via devtools::install_github('sinhrks/ggfortify')). You can now provide label.show.legend, e.g.

autoplot(prcomp(df), data = iris, colour = 'Species', label = TRUE, label.size = 3, label.show.legend = FALSE)

This should fix the "a" issue. Let me know if it fixes things for you. Thanks!

obenno commented 6 years ago

Thanks a lot, it perfectly works!

Jahadsoorni commented 4 years ago

I just pushed an update (install via devtools::install_github('sinhrks/ggfortify')). You can now provide label.show.legend, e.g.

autoplot(prcomp(df), data = iris, colour = 'Species', label = TRUE, label.size = 3, label.show.legend = FALSE)

This should fix the "a" issue. Let me know if it fixes things for you. Thanks!

Hi, I had a same problem with "fviz_pca_biplot()" and fixed with "label.show.legend = FALSE". Thanks.