Reputation: 10893
I'm trying add to my plot some data that will facilitate users. My distribution graph comes from this code:
require(ggplot2)
my_data<-c(70, 71, 75, 78, 78, 79, 80, 81, 84, 85, 87, 87, 90, 91, 95, 95, 96, 96, 97, 98, 98, 100, 101, 102, 102, 102, 102, 104, 104, 104, 107, 107, 109, 110, 110, 110, 111, 112, 113, 113, 114, 115, 118, 118, 118, 120, 124, 131, 137, 137, 139, 145, 158, 160, 162, 165, 169, 177, 179, 180)
dist <- dnorm(my_data,mean=mean(my_data), sd(my_data))
qplot(my_data,dist,geom="line")+xlab("x values")+ylab("Density")+ ggtitle("cool graph Distribution") + geom_line(color="black")
and the result is:
What I'm aiming to do is to add more data to the ggplot2:
Thanks for any pointers!
desired result:
Upvotes: 0
Views: 554
Reputation: 18657
You can add various lines to the chart using geom_line
, I reckon that it's only a matter of placing lines at different points that you want to highlight on the chart (mean, etc.):
qplot(my_data,dist,geom="line") +
xlab("x values") +
ylab("Density") +
ggtitle("cool graph Distribution") +
geom_line(color="black") +
geom_line(stat = "hline", yintercept = "mean", colour = "blue") +
geom_line(stat = "vline", xintercept = "mean", colour = "red")
Upvotes: 1