2017-09-21 123 views
1

有了這個代碼標記點:去除ggplot

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」標籤?

感謝您的幫助!

回答

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