根据另一个变量

时间:2015-07-10 16:55:04

标签: r boxplot

我对R来说相当新,并会欣赏一些意见。我为每个波创建了一个最多有4个箱图的图(1-5)。我现在想在情节上显示某些符号的符号。例如,我想显示id = 202的响应(id也在数据'mydata'中)。我搜索了高低,无法弄清楚如何做到这一点。有什么想法吗?这是我的代码(似乎我不能在没有10个声誉的情况下发布我的图片):

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())

1 个答案:

答案 0 :(得分:1)

您所要求的并不完全清楚,但也许您可以使用其中一个内置数据集构建示例。例如,我认为这可能是你所追求的:

# 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)

Results