geom_vline() not inheriting data within mean() function

40 views
Skip to first unread message

Timothy Lau

unread,
Aug 15, 2017, 4:16:59 PM8/15/17
to ggplot2
Hi all,

I'm back with another NOOB question.

Is there a way to get
mean()
to use the data available in
geom_vline()
?

e.g.,
ggplot(data = women, mapping = aes(x = height, y = weight)) + geom_point() + geom_vline(xintercept = mean(height))

won't work but:
ggplot(data = women, mapping = aes(x = height, y = weight)) + geom_point() + geom_vline(xintercept = mean(women$height))
will.



Best,
Timothy

Timothy Lau

unread,
Aug 15, 2017, 4:23:19 PM8/15/17
to ggplot2
This is the same if you use dplyr:
women %>%
    ggplot
(mapping = aes(x = height, y = weight)) + geom_point() + geom_vline(xintercept = summarize(mean(height)))

san mohan

unread,
Aug 17, 2017, 4:51:32 AM8/17/17
to ggplot2
Use aes:    

ggplot(data = women, mapping = aes(x = height, y = weight)) + geom_point() + geom_vline( aes(xintercept = mean(height)))
Reply all
Reply to author
Forward
0 new messages