the inclusion of ggrepel in ggplot leads funny shape in legend:
q: how replace normal shape?
sample code:
data(mtcars) library(ggplot2) library(ggrepel) ggplot(mtcars, aes(x = mpg, y = wt, color = factor(vs), size = factor(cyl))) + geom_point() + geom_text_repel(aes(label = rownames(mtcars)), size = 5)
sessioninfo:
r version 3.2.3 (2015-12-10) platform: x86_64-pc-linux-gnu (64-bit) running under: ubuntu 16.04.1 lts locale: [1] lc_ctype=en_us.utf-8 lc_numeric=c lc_time=nl_nl.utf-8 lc_collate=en_us.utf-8 lc_monetary=nl_nl.utf-8 lc_messages=en_us.utf-8 lc_paper=nl_nl.utf-8 [8] lc_name=c lc_address=c lc_telephone=c lc_measurement=nl_nl.utf-8 lc_identification=c attached base packages: [1] stats graphics grdevices utils datasets methods base other attached packages: [1] magrittr_1.5 ggrepel_0.5 ggplot2_2.1.0.9000 loaded via namespace (and not attached): [1] labeling_0.3 colorspace_1.2-6 scales_0.4.0 assertthat_0.1 plyr_1.8.4 rsconnect_0.4.3 tools_3.2.3 gtable_0.2.0 tibble_1.1 rcpp_0.12.6 grid_3.2.3 digest_0.6.10 [13] munsell_0.4.3
ggrepel has show.legend
argument, need show.legend = false
below:
show.legend
logical. should layer included in legends? na, default, includes if aesthetics mapped. false never includes, , true includes.
ggplot(mtcars, aes(x = mpg, y = wt, color = factor(vs), size = factor(cyl))) + geom_point() + geom_text_repel(aes(label = rownames(mtcars)), size = 5, show.legend = false)
as side note, prepare data outside ggplot clarity:
#fix data plotdat <- mtcars plotdat$vs <- as.factor(plotdat$vs) plotdat$cyl <- as.numeric(as.factor(plotdat$cyl)) plotdat$mylabel <- rownames(plotdat) #then plot ggplot(plotdat, aes(x = mpg, y = wt, color = vs, size = cyl, label = mylabel)) + geom_point() + geom_text_repel(size = 5, show.legend = false)
Comments
Post a Comment