Reputation: 13
I'm fairly new to R and would appreciate some input. I've created a plot with up to 4 boxplots for each wave (1-5). I would now like to display symbols on the plot for someone responses based on their id. For instance, I want to show the responses where id=202 (id is also in data 'mydata'). I've searched high and low, and cannot figure out how to do it. Any thoughts? Here's my code (it seems I can't post my image without a 10 reputation):
ggplot(aes(y=InnAttMeasure, x=interaction(IntType, wave)), data=mydata)+
geom_boxplot(aes(fill=factor(IntType)))+
stat_summary(fun.y="mean", geom="point", shape=23, size=3, fill="black") +
scale_fill_brewer()+
xlab("Wave") +
ylab("Innovation Attribute Measure (1-7)" ) +
facet_grid(.~wave, scales="free", space="free") +
coord_cartesian(ylim=c(0,7.5)) +
scale_y_continuous(breaks=seq(0,7,1)) +
scale_x_discrete(breaks=NULL) +
theme(panel.grid.minor.y=element_blank(),
panel.grid.major.y=element_blank())
Upvotes: 1
Views: 3586
Reputation: 20483
It's not entirely clear what you're asking, but perhaps you can construct an example using one of the built-in datasets. For example, I think this might be what you're after:
# First look at the mtcars dataset
mtcars
library(ggplot2)
# Let's make a dataframe of just the Mercedes cars; lots of ways to do this.
mercedes <- mtcars[grep("Merc", row.names(mtcars)), ]
# Now plot a boxplot of mpg by cylinder and then overlay points geom_point()
# of just the Mercedes dataframe
ggplot(data = mtcars, aes(y = mpg, x = factor(cyl))) +
geom_boxplot() +
geom_point(data = mercedes, color = "blue", position = "jitter", size = 4)
Upvotes: 1