Single geom_point on a violin plot?

31 views
Skip to first unread message

Carl

unread,
Jul 28, 2016, 6:56:40 AM7/28/16
to ggplot2
I suspect my question is a dumb one, but I've been struggling. I plotted 150 observations onto a violin plot (weekly price to book valuations for a stock) I would like to add a geom_point to highlight the last observation in the data to show what the most recent price-to-book value is. I've tried doing + geom_point(data, aes(row(150)) along with multiple other angles.

Any input would be great and thanks in advance!

Brian

unread,
Jul 28, 2016, 7:29:53 AM7/28/16
to Carl, ggplot2
you may check out stat_summary.

Here's a guess:

stat_summary(fun.y = function(x) x[length(x)])

Carl

unread,
Jul 28, 2016, 10:21:56 AM7/28/16
to ggplot2
Oh yes - thanks so much! I spent way too much time on this so I really appreciate it. I added a geom_point along with a 2 StDev range bar and quantile distribution.

Here is what I have:

v <- Ticker

v2<- ggplot(Ticker, aes(Stock, PB))


v2 + geom_violin(draw_quantiles = c(.10, .20, .30, .40, .50, .60, .70, .80, .90), adjust = .50) +
stat_summary(fun.data = "mean_sdl", fun.args = list(mult=2), geom = "pointrange", color = "green") +
ggtitle("Historical Trading Range by Price-to-Book. 4.5 Yr Period") + stat_summary(fun.y = function(x) x[length(x)], geom = "point", color = "blue", size = 4)

Is this working because of the "length" condition, meaning it returns the last observation regardless of the number of rows?

Thanks again!

Reply all
Reply to author
Forward
0 new messages