r - How can I add freehand red circles to a ggplot2 graph? -


last year posted an analysis of user activity meta stack overflow, including series of ggplot2 graphs. however, wooble shamed me pointing out fatal flaw plots:

enter image description here

freehand red circles are of course necessary in plot on meta stack overflow, dismay not find way add them ggplot2 graph. know how add circle, such artificial construct has no personality , never pass muster on meta.

as reproducible example, consider plot of own answering activity on time, created using stackr package:

# devtools::install_github("dgrtwo/stackr") library(ggplot2) library(dplyr) library(lubridate) library(stackr)  answers <- stack_users(712603, "answers", num_pages = 10, pagesize = 100) answers_per_month <- answers %>%     mutate(month = round_date(creation_date, "month")) %>%     count(month)  ggplot(answers_per_month, aes(month, n)) + geom_line() 

without freehand

this plot informative enough, has no soul. how can add freehand red circles it?

you can use ggfreehand package, provides geom_freehand layer carelessly omitted ggplot2.

for example, if wanted circle top 2 active months in plot above, follow code with:

top_2_months <- answers_per_month %>% top_n(2)  library(ggfreehand) ggplot(answers_per_month, aes(month, n)) + geom_line() +     geom_freehand(data = top_2_months) 

with freehand

and that, plot worthy of being posted on meta stack overflow.

the geom_freehand layer takes additional options customize circle, including radius , noisiness. make circle not red, though ever want do.

p <- ggplot(answers_per_month, aes(month, n)) + geom_line()  p + geom_freehand(data = top_2, radius = .5) p + geom_freehand(data = top_2, noisiness = 10) p + geom_freehand(data = top_2, noisiness = 1) p + geom_freehand(data = top_2, color = "blue") 

enter image description here


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -