删除ggplot中的标记点

时间:2017-09-21 04:21:26

标签: r ggplot2 reshape2

使用此代码:

week1 <- c(6,3,1,2,8,7,5,10,4,9)
week2 <- c(3,2,1,4,9,10,5,8,6,7)

dat <- data.frame(week1, week2)
dat$team <- c("team a", "team b", "team c", "team d", "team e", "team f", "team g", "team h", 
                 "team i", "team j")

a <- melt(dat, id.vars="team",
          measure.vars = grep("^week",names(dat),value=TRUE))

ggplot(a, aes(x=variable, y=value,color=team)) +
  geom_point() +
  geom_line(aes(group = team)) + 
  scale_y_continuous(breaks = seq(1,10,1),trans = "reverse") +
  geom_text(aes(label=team),hjust=-0.5)

我得到这张图表:

chart

我想知道的是如何仅删除“week1”上的标签?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

条件标签。

ggplot(a, aes(x=variable, y=value,color=team)) +
  geom_point() +
  geom_line(aes(group = team)) + 
  scale_y_continuous(breaks = seq(1,10,1),trans = "reverse") + geom_text(aes(label=team), data = a[a$variable == 'week2',])

截图: enter image description here