Highlight individual observation in density and violin plot in R/ggplot2 -
i trying highlight position of individual in density plot , in violin plot.
for instance, in plot generated code bellow, highlight "mazda rx4" in mtcars dataset. adding point or bar value of individual observation in each category
#density plot ggplot(data=mtcars,aes(x=drat))+ geom_density() + facet_grid(cyl ~ .) #violin plot library(ggplot2) ggplot(data=mtcars,aes(x=factor(cyl),y=drat, fill=factor(am)))+ geom_violin()
edit: 1) based on @dataminer answer bellow able add desired point (code bellow) violin plot.
ggplot(data=mtcars,aes(x=factor(cyl),y=drat, fill=factor(am)))+ geom_violin() + geom_point(data = mtcars[rownames(mtcars) == "mazda rx4",])
however, same +geom_point() did not work density plot. how can add point observation density plot?
2) also, possible use marker, line segment or bar (perpendicular base line of distribution) instead of point?
try following first part of question (add ggplot-code):
geom_point(data = mtcars[rownames(mtcars) == "mazda rx4",])
for second part of question can try(add ggplot-code):
geom_point(data = mtcars[rownames(mtcars) == "mazda rx4",], aes(y = 0))
Comments
Post a Comment